Github SSH Connection Linux Setup

The recommended and possible simplest way to connect and authenticate to Github is to use the SSH key-based authentication. In order to set it up under Linux the following steps are to be taken.

First generate a key if you don’t have one. If the directory .ssh doesn’t exist then create it first. Make sure that the name you use for the key (here id_ed25519) is not yet present in the directory. It can be useful to give a name or “comment” to the key.

ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/id_ed25519

In order to use the key, start the ssh-agent and add the key. To automatically load your SSH key in every new terminal session, start the ssh-agent and add the key in your .bashrc or .zshrc file.

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

You have to store the public part of the key in Github in order to use it. Display the public key in the terminal and copy it.

cat ~/.ssh/id_ed25519.pub

Navigate to GitHub SSH Keys Settings and press the “New SSH Key” button and paste the key that you copied in the previous step.

To check if the connection has been setup properly run the following command.

ssh -T git@github.com

If everything went well, you should see a response like this: Hi ! You've successfully authenticated, but GitHub does not provide shell access.

If you wonder why ed25519 encryption algorithm was used to generate the key, the answer is simple. It provides stronger security with a smaller key length compared to RSA. If it is supported (and Github fully supports it) then it is always preferred over RSA.