我有一个名为nms.example.org的主机。在我/etc/ssh/ssh_known_hosts
的主机中,我有一个带RSA密钥的主机条目。该条目以及所有其他条目均由我的配置管理系统管理。
nms.example.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZqfmVPs/XqTS...
另外,我/etc/ssh/ssh_config
在特定主机的条目中设置了主机密钥别名。如果我正确理解所有内容,则意味着仅nms.example.org
应注意。
Host nms.example.org nms.example nms
HostKeyAlias nms.example.org
HostName nms.example.org
为什么然后,当我从客户端连接时,ssh似乎仍然认为它需要使用主机的IP向我的每用户known_hosts添加密钥?
$ ssh nms -v
OpenSSH_6.0p1 Debian-4+deb7u4, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /home/zoredache/.ssh/config
debug1: /home/zoredache/.ssh/config line 61: Applying options for *
debug1: /home/zoredache/.ssh/config line 71: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 84: Applying options for nms
debug1: /etc/ssh/ssh_config line 363: Applying options for *
debug1: Connecting to nms.example.org [104.236.190.144] port 22.
debug1: Connection established.
debug1: identity file /home/zoredache/.ssh/zoredache-20140204.id_rsa type 1
...
debug1: Server host key: RSA 6b:5f:b6:e9:13:c3:b7:39:1e:ec:74:05:33:64:4d:5e
debug1: using hostkeyalias: nms.example.org
debug1: Host 'nms.example.org' is known and matches the RSA host key.
debug1: Found key in /etc/ssh/ssh_known_hosts:104
Warning: Permanently added the RSA host key for IP address '192.0.2.144' to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
...
SSH知道我的主机有效(请参阅Host 'nms.example.org' is known and matches the RSA host key
:),为什么它将IP的密钥添加到用户配置文件?
这非常令人讨厌,因为当我重新安装计算机时,我的配置管理系统可以很好地处理主机密钥的收集和分发。但是,在每次使用的known_host文件中,与IP关联的这些遗留冲突密钥会在连接尝试中引起警告,从而阻止脚本连接。
$ ssh nms -v
OpenSSH_6.0p1 Debian-4+deb7u4, OpenSSL 1.0.1e 11 Feb 2013
...
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u4
debug1: using hostkeyalias: nms.example.org
...
debug1: Server host key: RSA 6b:5f:b6:e9:13:c3:b7:39:1e:ec:74:05:33:64:4d:5e
debug1: using hostkeyalias: nms.example.org
debug1: Host 'nms.example.org' is known and matches the RSA host key.
debug1: Found key in /etc/ssh/ssh_known_hosts:104
Warning: the RSA host key for 'nms.example.org' differs from the key for the IP address '192.0.2.144'
Offending key for IP in /home/zoredache/.ssh/known_hosts:25
Matching host key in /etc/ssh/ssh_known_hosts:104
Are you sure you want to continue connecting (yes/no)?
如何防止ssh在每个用户known_hosts中缓存此基于IP的值?还是出于某种安全原因,我不得不忍受这种令人讨厌的行为?这也让我感到沮丧,因为几个服务器具有一些动态IP地址。我的配置管理处理DNS更新。但是我将这些遗留在每个IP主机密钥中,这些密钥填充了每个用户的known_host文件。