Using GitHub with multiple SSH keys

Great for managing work and personal accounts

Create two keys

$ ssh-keygen -t rsa -C ""
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mriddle/.ssh/id_rsa):

The keys I created were:


If you’re starting fresh clear any previously cached keys

$ ssh-add -D

Add your new SSH keys

$ ssh-add ~/.ssh/
$ ssh-add ~/.ssh/id_rsa.home

Make sure they’re added

$ ssh-add -l

Update the config to use the new keys

# In this configuration the work key will be my default for github and home is my secondary
# more on this below
$ vi ~/.ssh/config

    User git
    IdentityFile ~/.ssh/id_rsa.home

    User git
    IdentityFile ~/.ssh/

IdentityFile ~/.ssh/
IdentityFile ~/.ssh/id_rsa.home

Update the home git repo to make use of our key by adding it to the repo git config

$ .git/config
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url =

Note: You only need to update the git config with key we setup as our secondary, in this case my home key. I can leave the .git/config alone for work projects.

Hope this helps :)


22 Nov 2012