Andres Jaimes

Installing git and connecting to GitHub on FreeBSD

By Andres Jaimes

- 5 minutes read - 907 words

Git is a popular version control system that allows developers to manage their code repositories efficiently. If you are a developer using FreeBSD, you will need to set up Git and an authentication method to start collaborating on projects with other developers. In this post, we will walk you through the process of installing Git, creating SSH keys, and cloning a project from GitHub on FreeBSD.

Does this work in Linux or Mac? Yes, it does. You just need to install git following your operating system’s instructions, if it’s not already installed.

Let’s start

Switch to the root user and install git:

su -
pkg install git
Message from git-2.39.2:

If you installed the GITWEB option please follow these instructions:

In the directory /usr/local/share/examples/git/gitweb you can find all files to
make gitweb work as a public repository on the web.

All you have to do to make gitweb work is:
1) Please be sure you're able to execute CGI scripts in
2) Set the GITWEB_CONFIG variable in your webserver's config to
   /usr/local/etc/git/gitweb.conf. This variable is passed to gitweb.cgi.
3) Restart server.

If you installed the CONTRIB option please note that the scripts are
installed in /usr/local/share/git-core/contrib. Some of them require
other ports to be installed (perl, python, etc), which you may need to
install manually.

The installation is complete, and we are ready to create a key-pair to use to authenticate against GitHub.

End your root user session and go back to your regular user prompt.

Creating a key-pair is a simple process and is accomplished by typing the following command:

ssh-keygen -t ed25519 -C "email-used-for-github@domain.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_ed25519
Your public key has been saved in /home/user/.ssh/id_ed25519.pub

It is ok to leave the passphrase empty, but it is important that you understand the implications.

The key-pair process creates a set of files, a public key, and a private key. They are stored in your ~/.ssh directory and named id_ed25519 for the private one, and id_ed25519.pub for the public one. Be very careful with these files and treat them like you treat passwords.

GitHub allows you to use SSH keys to authenticate. They can be added on the settings/keys page. You can navigate to it by going to Settings, and then selecting SSH and GPG keys. To add a new ssh key:

  1. Press the New SSH key button, then
  2. Enter a description in the Title field, then
  3. Copy the contents of the generated public key (the id_ed25519.pub file you just created)
cat ~/.ssh/id_ed25519
ssh-ed25519 .................
  1. And paste it into the Key field in GitHub: Pasting the public key contents into the key field in GitHub

  2. Press the Add SSH key button to finish.

You should now see your SSH key added to GitHub:

Once you are done setting up the keys, we are ready to clone our first project. On GitHub, go to your repositories and select a private project, then click on Code and select SSH. Copy the url that shows up.

Selecting the SSH url from github

Type the following command using the URL you just copied:

git clone git@github.com:user/project.git
Cloning into 'project'...
remote: Enumerating objects: 115, done.
remote: Counting objects: 100% (115/115), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 115 (delta 29), reused 111 (delta 25), pack-reused 0
Receiving objects: 100% (115/115), 22.68 KiB | 7.56 MiB/s, done.
Resolving deltas: 100% (29/29), done.

Voila! The project should be successfully cloned using the keys that we created previously to authenticate against GitHub.

Git is an essential tool for any developer who wants to collaborate on code repositories with other developers. By following the steps outlined in this post, you’ll be able to install Git, create SSH keys, and clone a project from GitHub on FreeBSD with ease. With these steps, you’ll be able to join a project and start collaborating with other developers in no time.


Skip this step if you are not using a Mac.

If you are using a Mac, you have to add the generated key to the ssh-agent.

Testing your connection

If the connection is failing, you can try the following:

Try to connect to github:

ssh -T git@github.com

And type yes to the following prompt:

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
> Are you sure you want to continue connecting (yes/no)?

Verify that the following message shows up:

> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.

If you are trying to git pull an existing project and git insists on using your username and password, then:

  1. Open the file .git/config in the project’s directory.
  2. Look for the [remote "origin"] section and verify that the url is set to use ssh. For example:
url = git@github.com:some-account/some-project.git

git will not work if the url is using the https protocol. If this is the case, get the ssh url from github and replace the value in this file.