Multiple deploy keys with git

Before I forget, and some may find this useful too.
If you are deploying a few projects to the same server you will run into this, you need to use unique deploy keys to access each project unless you want to add the server’s public key to your account. For security reasons I did not want to do that.

First generate some deployment keys with ssh-keygen. Here’s some more info on adding your deploy keys to your git repo

So I need to set up my ssh config file in ~/.ssh/config like so…

Host project-a
  HostName github.com
  User git
  IdentityFile ~/.ssh/deploy_key_a_rsa
  IdentitiesOnly yes

Host project-b
  HostName github.com
  User git
  IdentityFile ~/.ssh/deploy_key__b_rsa
  IdentitiesOnly yes

Let’s say your two project git urls look like this:

  git@github.com:anon/project-a.git
  git@github.com:anon/project-b.git

You can now clone with the correct keys using..

  $> git clone project-a:anon/project-a.git
  $> git clone project-b:anon/project-b.git