Skip to content

Setting up SSH based access to GitHub

trz42 edited this page Feb 7, 2023 · 2 revisions

Generate an SSH key pair with a passphrase

ssh-keygen -t ed25519 -f ~/.ssh/id_gh_nessi

Type in a passphrase. It needs to be strong. No big deal if you forget it, just repeat the steps to create a new one.

Upload the public part of the SSH key pair to your GH user

  1. Open https://github.com/settings/keys
  2. Click “New SSH key”
  3. Provide a meaningful name and set key type to “Authentication key”
  4. Paste in the public part of the key (display it on your machine with cat ~/.ssh/id_gh_nessi.pub)

Test the key is working

In a terminal run

ssh -i ~/.ssh/id_gh_nessi -T [email protected]

You should be asked to type in the passphrase of the key. If the test is successful you should see something like:

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

Setting up an SSH agent

To avoid that you have to type in your passphrase again and again, you can set up an ssh-agent and store your key with it. You only have to type in the passphrase of the key once.

  1. Launch ssh-agent in your shell (note has to be done for every shell)
eval$(ssh-agent -s)
  1. Add your SSH key pair to the agent
ssh-add ~/.ssh/id_gh_nessi

Type in the passphrase for the key. 3. Try again to authenticate against GitHub

ssh -T [email protected] -i ~/.ssh/id_gh_nessi

Should show something like below without asking for the passphrase.

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

One more step to easily integrate with GitHub & git commands

Add a section to your ~/.ssh/config

Host gh-nessi
Hostname github.com
IdentitiesOnly yes
IdentityFile ~/.ssh/id_gh_nessi