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

拜拜、爱过 提交于 2019-12-03 12:57:58

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/8171613/how-to-use-special-ssh-key-for-bitbucket-and-github-to-push-pull

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!