culebrón culebrón - 11 months ago 52
Git Question

How to use special SSH key for BitBucket and GitHub to push/pull?

I had Ubuntu 10.04 and recently upgraded to 11.10. Additional SSH keys stopped working. I have keys

, which I have in the websites. How can I tell SSH to use one particular key for Bitbucket and another for GitHub?

So, I have a config:

Host bitbucket
User hg
IdentityFile ~/.ssh/bitbucket

When I call
ssh bitbucket
, ssh successfully logs in with the key and gets kicked out. But when I try
hg pull
, I see "no response from remote hg." and the passphrase is not asked.

What can be done?

Answer Source

For the little explanation on why the config posted in the question doesn't work but your answer does :

When you call ssh bitbucket, ssh looks in your config file for a host named bitbucket which is defined with the Host keyword. Then, using the HostName keyword, you can define the real hostname to use. In your case, you're defining bitbucket as an alias for the IP which I assume is the one for

It wasn't working for your mercurial commands because the remote server is probably defined as and not the alias bitbucket. After you changed the config file to the one proposed in your answer, ssh can effectively match the remote server to the host name and everything is fine !

FYI, you can also use wildcard for the pattern matching, for example :

Host bitbucket.*
    User hg
    IdentityFile ~/.ssh/bitbucket

Would also work, because when looking at the config, SSH will replace the * with anything else.