Roland's homepage

My random knot in the Web

Switching to SSH keys for github

This article covers some aspects of using SSH keys with github that are left out of the original documentation on github.

It assumes that you’ve been using HTTPS with a password for remote access to github.


In this article, text between angle brackets (like <user>) are used as placeholders for actual strings that you have to provide.

Mostly follow the documentation

There is documentation on github how to generate an SSH key for use with github. It is mostly ok to follow this, but it lacks some final pieces.


Keep in mind to select Linux at the top of this documentation. Otherwise you will not see all commands!

In contrast to what is mentioned there, I would suggest generating a separate key only for github, using the -f argument of ssh-keygen.

ssh-keygen -t ed25519 -C <user>@<provider.tld> -f /home/<user>/.ssh/id_github

Starting the ssh-agent and adding the key to the agent is covered in the aforementioned documentation. As is uploading the public key to github.

There are two missing pieces:

  • Configuring SSH
  • Converting your repositories

Configure SSH

What is missing is how to set up SSH. For this you will have to edit your ~/.ssh-config.

You will need to add the following lines to it:

    IdentityFile ~/.ssh/id_github

Updating your repositories

For every repository that has a remote on github, you have to change the URL. The original will be<github-user>/<Project>.git. This will need to be changed to<github-user>/<Project>.git

You can find the remotes in your repositories by running the following command from your home-directory.

find . -type f -path '*.git/config' | xargs grep -B 1 -H 'url.*<github-user>/' {} \; | less

Now you will have to change directory to every repository and issue the following command, where <github-user> should be replaced by your github user name and <project> should be replaced by the project name.

git remote set-url origin<github-user>/<project>.git

After you have done this, you will be asked for your SSH key passphrase when running git push.

For comments, please send me an e-mail.

←  On the nature of GUI programs Why can’t a piece of software be finished?  →