GitHub logo

Since starting working at ScraperWiki, I've been using Git version control and GitHub a lot to collaborate on projects I'm working on. Out of the box, connecting to GitHub via HTTPS is simple to get going and works perfectly fine. One problem is that you have to enter a username and password every time you do anything with the remote repository, such as pushing code to it.

For me, this gets in the way of workflow. It's a small, but distracting, obstacle that snaps me out of whatever thought process I was in. Over a full day's work, this can happen several times.

Instead, I prefer to connect to GitHub using an SSH connection. All I do now is enter a passphrase once per login session and then forget about it1. Another advantage is that you can forward access to your local SSH credentials even when developing in remote shell accounts.

GitHub's help section has several well written pages that detail clearly how to get this setup running. The only issue with those guides is that the individual steps are actually split over a few individual help pages. Here's a combined summary of what you need to do.

  1. Generate an SSH key locally (not on a remote shell account), with a passphrase, add it to your GitHub account and test it.

    You should now change the clone URLs GitHub displays to SSH (see the image; where it says clone with HTTPS, SSH..., click on SSH).

    GitHub sidebar showing the position of the clone URL display.

    Now, the first time you try to perform some action on GitHub via ssh (e.g. git clone), you should only get asked for the passphrase once and subsequent connections will proceed without prompting. This worked out of the box for me on Ubuntu 12.04 LTS. If you have issues, you'll need to look into how to configure ssh-agent on your system.

    Bear in mind that if you already have repositories that you have cloned via HTTPS using GitHub, you'll likely want to update the git remotes to use the appropriate SSH URLs instead. These won't be automatically changed. Otherwise you'll still get asked for your username and password credentials: these local repositories will still be connecting via HTTPS URLs!

  2. (Optional; handy if you're developing or git cloning on remote boxes) With everything now working locally, you need to setup ssh-agent so that your remote account can access your SSH key.

When you now carry out an operation with GitHub on the remote machine you connected to via SSH, you shouldn't get asked for your password on that machine either2.


  1. I am aware that you do have the option of using credential helper to cache your HTTPS password, but you would need to do this both locally and remotely if you are working on different machines. Also, the default setting, though it can be changed, is to cache the password for just 15 minutes. 

  2. Again, the caveat regarding changing repository remote settings from HTTPS to SSH applies on remote machines too.