Multiple SSH keys and Git

November 27, 2012

I have three different ssh keys set up: id_rsa.mcgill for my McGill site, id_rsa.github for GitHub, and id_rsa.bitbucket for BitBucket. I also have the following in my ~/.ssh/config:

Now, it had been a while since I manually ssh-ed into GitHub or even McGill. I update my McGill site with a simple rsync command that includes the -i option specifying the ssh identity file to use.

So I was confused recently when, each time I tried to ssh into GitHub or McGill, I would get this error:

The solution, it turns out, is that if the identity file is named something other than id_rsa or id_dsa, then running ssh user@hostname (without the -i option) will not find it. That should’ve been immediately obvious to me: the whole point of an ssh config file like the one I set up months ago is to not have to type out user@hostname!

So all I had to do was stop typing git@github and instead use simply github (or whatever comes after Host in the config; that’s up to you). So all of these should work, and they do: