Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 bitbucket and github, 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
HostName 207.223.240.182
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?

like image 492
culebrón Avatar asked Nov 17 '11 17:11

culebrón


2 Answers

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 207.233.240.182 which I assume is the one for bitbucket.org

It wasn't working for your mercurial commands because the remote server is probably defined as bitbucket.org 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.*
    HostName 207.223.240.182
    User hg
    IdentityFile ~/.ssh/bitbucket

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

like image 90
krtek Avatar answered Sep 29 '22 04:09

krtek


I didn't try hard enough! The key is there now. Solution was to add .org to host:

Host bitbucket.org
User hg
IdentityFile ~/.ssh/bitbucket2
like image 39
culebrón Avatar answered Sep 29 '22 02:09

culebrón