为什么 SSH 为 IP 地址添加known_host 条目?

为什么 SSH 为 IP 地址添加known_host 条目?

我有一个名为 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 似乎仍然认为它需要使用以下命令向我的每个用户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 文件。

答案1

我认为这是为了完成CheckHostIP工作。

如果此标志设置为“yes”,ssh(1) 将另外检查文件中的主机 IP 地址known_hosts。这允许 ssh 检测主机密钥是否由于 DNS 欺骗而更改。如果该选项设置为“否”,则不会执行检查。默认为“是”。

如果使用此选项发生错误配置或攻击,您会得到稍微更好的诊断,但它实际上并没有以我能想到的任何方式提高安全性。

如果关闭,CheckHostIP则当您按名称连接到新主机时,SSH(从 OpenSSH 6.7p1 开始)不会记录 IP 地址。因此,将其添加到您的.ssh/config

CheckHostIP no

Host如果您只想为特定主机(尤其是具有动态 IP 地址的主机)关闭它,则可以将其添加到某个部分。

相关内容