如何使用BitBucket和GitHub的特殊SSH密钥来推/拉? [英] How to use special SSH key for BitBucket and GitHub to push/pull?

查看:120
本文介绍了如何使用BitBucket和GitHub的特殊SSH密钥来推/拉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Ubuntu 10.04,最近升级到11.10。额外的SSH密钥停止工作。我有网站中的密钥 bitbucket github 。我怎么能告诉SSH使用一个特定的密钥为Bitbucket和另一个为GitHub?



所以,我有一个配置:

 主机bitbucket 
主机名207.223.240.182
用户hg
IdentityFile〜/ .ssh / bitbucket

当我调用 ssh bitbucket 时,ssh成功使用密钥登录并被踢出。但是当我尝试 hg pull 时,我看到远程hg没有响应。并且不会询问密码。



可以做什么? 解决方案



当您调用 ssh bitbucket

时,为什么发布的问题中的配置不起作用, / code>,ssh会在您的配置文件中查找名为 bitbucket 的主机,该主机由主机关键词。然后,使用 HostName 关键字,您可以定义要使用的真实主机名。在你的情况下,你定义了 bitbucket 作为IP 207.233.240.182的别名,我假设它是 bitbucket.org $ b

它不适用于您的mercurial命令,因为远程服务器可能定义为 bitbucket.org 而不是别名 bitbucket 。在您将配置文件更改为您的答案中提出的配置文件后,ssh可以有效地将远程服务器与主机名相匹配,并且一切正常!

仅供参考,您也可以使用通配符进行模式匹配,例如:

 主机bitbucket。* 
HostName 207.223.240.182
用户hg
IdentityFile〜/ .ssh / bitbucket

也可以,因为在看在配置中,SSH将用其他的替换*。

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?

解决方案

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.

这篇关于如何使用BitBucket和GitHub的特殊SSH密钥来推/拉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆