我有一种情况,需要使用两个不同的SSH密钥访问相同的SSH主机(GitHub)。 这是没有问题的,我可以很容易地通过别名主机名来设置它。 当这个configuration与我的SSH多路复用configuration相结合时,问题出现了。 我似乎无法用主机特定的声明覆盖我的默认ControlPath。
也许这只是它的工作方式? 也许这是一个错误? 难道我做错了什么?
顺便说一句,我在Mac 10.7上。
这是我的configuration:
Host * ControlMaster auto ControlPath ~/.ssh/connections/ssh-%r@%h:%p Host github.com-X TCPKeepAlive yes ServerAliveInterval 60 ControlPersist 1h Hostname github.com User git IdentityFile ~/.ssh/id_rsa_X IdentitiesOnly yes ControlPath ~/.ssh/connections/ssh-%r@%hX:%p Host github.com TCPKeepAlive yes ServerAliveInterval 60 ControlPersist 1h
我已经修改了一点点,但似乎总是得到Host *声明中指定的ControlPath。
ssh -T [email protected]
使用id_rsa_X以正确的用户身份login,但在此创build域套接字:
~/.ssh/connections/[email protected]:22
而不是:
~/.ssh/connections/[email protected]:22
所以后来当我尝试使用id_rsa发出SSH命令时,由于连接复用,我得到了id_rsa_X用户。 换一种说法:
ssh -T [email protected]
给我一个关于id_rsa_X的用户的hello消息。
有任何想法吗?
编辑:响应评论vgoff – 不,它似乎是阅读我所有的configuration…
$ ssh -vT [email protected] OpenSSH_5.6p1, OpenSSL 0.9.8y 5 Feb 2013 debug1: Reading configuration data /Users/<username>/.ssh/config debug1: Applying options for * debug1: Applying options for github.com-X debug1: Reading configuration data /etc/ssh_config debug1: Applying options for * debug1: auto-mux: Trying existing master debug1: Control socket "/Users/<username>/.ssh/connections/[email protected]:22" does not exist <snip>
您可以看到它读取所有设置并尝试使用错误的ControlPath。
你需要在~/.ssh/config
进一步减less特定的选项。 Host *
选项首先被应用,并且不会被以后的冲突,选项覆盖,即使它们更具体。 然而, Host *
中未指定的新选项将被应用,我认为这是您在日志中看到的。
资料来源: http : //linux.die.net/man/5/ssh_config
ssh(1)按以下顺序从以下源获取configuration数据:
- 命令行选项
- 用户的configuration文件(〜/ .ssh / config)
- 系统范围的configuration文件(/ etc / ssh / ssh_config)
对于每个参数,将使用第一个获得的值。 configuration文件包含由“主机”规范分隔的部分,该部分仅适用于与规范中给出的模式匹配的主机。 匹配的主机名是在命令行中给出的名称。
由于使用了第一个获得的每个参数的值,因此应该在文件的开头附近给出更多的主机特定的声明,并在结尾处给出一般的默认值 。