gcb*_*gcb 5 linux ssh openssh macos
我有一个~/.ssh/config工作正常的文件。它是这种格式:
Host *
IdentityFile ~/.ssh/id_null
TCPKeepAlive no
ServerAliveCountMax 5000
Host *.domain.com
User mydomainuser
IdentityFile ~/.ssh/id_domain
Host github.com
User gcb
IdentityFile ~/.ssh/id_domain
Run Code Online (Sandbox Code Playgroud)
(它有更多的域,但让我们暂时忽略它们)
它工作得很好,即使手册说更具体的主机模式应该放在最上面,它总是这样工作得很好。我总是通过 ssh 连接到这两个域,并且可以很好地获取正确的身份密钥。我从来没有遇到过对这两个域尝试使用空键的问题。我用了很多年。始终获得正确的用户和密钥。我在 debian、fedora 和 osx 上都使用了相同的配置文件。
今天,在OSX 10.10(OpenSSH_6.2p2,OSSLShim 0.9.8r 8 2011年12月),这工作之前,我想还可以添加User unkown到*顶部规则。突然之间,现在我每次尝试 ssh,ssh 都会发送 user=unkown 和 identityfile=id_null,它们不会在任何地方登录。这让我去阅读 ssh_config 的手册页,并完全按照书本保留所有内容......但它仍然无法正常工作。我也尝试User从中删除条目,*但这并没有解决它。
我当前的.ssh/config文件是
Host exact.hostname.domain.com
User mydomainuser
IdentityFile ~/.ssh/id_domain
Host *.domain.com
User mydomainuser
IdentityFile ~/.ssh/id_domain
Host github.com
User gcb
IdentityFile ~/.ssh/id_domain
Host *
IdentityFile ~/.ssh/id_null
TCPKeepAlive no
ServerAliveCountMax 50
Run Code Online (Sandbox Code Playgroud)
当 i 时,它仍然会尝试使用 id_null 作为身份文件ssh exact.hostname.domain.com。我也尝试使用多种模式,Host *.domain.com exact.hostname.domain.com而不是重复。什么都行不通。任何想法有什么问题?
我如何拥有默认值User并IdentityFile在每个域的基础上覆盖它们?
编辑1:我Host exact.hostname.domain.com在之前和之后都添加了*。并ssh -vvv显示:
debug1: /Users/.../.ssh/config line 1: Applying options for exact.hostname.domain.com
debug1: /Users/.../.ssh/config line 19: Applying options for *
debug1: /Users/.../.ssh/config line 37: Applying options for exact.hostname.domain.com
Run Code Online (Sandbox Code Playgroud)
但我还是到了最后 no such identity: .ssh/id_null: No such file or directory
编辑 2:我看到的其他一些奇怪的东西 ssh -vvv
它总是尝试使用我拥有的所有密钥。所以我想,因为它可能有一些硬编码的默认值.ssh/id_rsa*,所以我移动了我所有的私钥来.ssh/keys/隐藏它的默认值,并更新了特定的Host条目......结果,它正在尝试来自所有主机条目的密钥!即使是没有匹配的!
回顾一下,我在文件的顶部和底部有一个特定的主机匹配(为了安全起见),然后是不匹配的主机,还有*一个。
但 ssh -vvv 显示:
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /Users/x/.ssh/keys/id_rsa_git (0x7f954b700530),
debug2: key: /Users/x/.ssh/keys/id_rsa (0x7f954b415700), explicit
debug2: key: /Users/x/.ssh/id_null (0x0), explicit
Run Code Online (Sandbox Code Playgroud)
.ssh/keys/id_rsa_git如果这是IdentityFile唯一提到的,Host github.com到底为什么要添加?为什么它最终会尝试发送,id_null即使它与Host exact.hostname.domain.com调试输出中所说的显式匹配debug1: /Users/.../.ssh/config line 1: Applying options for exact.hostname.domain.com?
编辑3:
在我将所有密钥移动到.ssh/keys/*并且只为每个主机指定密钥之后ssh_config,现在我在每个ssh实例化中看到:
/Users/me/.ssh/id_*[^p][^u][^b]: No such file or directory
但即使在那之后,它仍然会在连接时从ssh_config 中的其他主机加载 IdentityFiles 。为什么?!
man ssh-config说:
由于使用每个参数的第一个获得的值,因此应在文件开头附近给出更多特定于主机的声明,并在末尾给出一般默认值。
因此,请确保您想要的配置位于第一个匹配的条目中Host,如匹配行所示ssh -vv :Applying options for。
在一般情况下,这意味着Host *应该是最后一个。
| 归档时间: |
|
| 查看次数: |
3943 次 |
| 最近记录: |