Tech Blog

Managing multiple SSH identities

Managing multiple SSH identities

Recently updated on

Here at Imaginary we maintain our own git repositories internally with the help of the invaluable utility, Gitolite. This works well for us. However, in some cases, our clients have their own repositories that we must interact with.

The problem arises when the client repositories reside on a third-party service, usually Github. As you likely know, Github uses ssh public-key authentication and before you can clone or push to repositories you need to register your public-key with the site.

The situation typically involves the client adding our company Github account as a collaborator on one of their repositories. If I attempt to add my personal public-key to our `imagescape' account, Github tells me that my key is already in use - a conflict with my personal Github account.

So the question then is: Is there an easy way to maintain two sets of ssh keys on my workstation and a mechanism for conveninently switching between them?

There is! 

The first thing you'll need is a second set of keys. Here is the command, just for reference:

    $ ssh-keygen -f ~/.ssh/id_rsa_iscape

Now we need to tell ssh to use this new keypair under certain circumstances. If you don't have one already, `touch ~/.ssh/config` and then open it up in your editor. Paste the following template and then edit it as appropriate:

    User git
    IdentityFile ~/.ssh/id_rsa_iscape
    PreferredAuthentications publickey 

Now in order to clone a repository shared with our company's Github account I simply use the new hostname as specified in the ssh configuration:

    $ git clone

If you have an existing repository that you want to update to this new system, simply edit the .git/config file and update the "url" setting for the remote you wish to change.


Comments are closed.