在/root/.ssh/known_hosts中为ssh和IP提供密钥

为什么或为什么我得到这个错误在服务器A试图连接到服务器B ?????

ssh [email protected] Warning: the ECDSA host key for 'zk.111.sf.development.cloudera.fu.com' differs from the key for the IP address '107.170.xxx.xxx' Offending key for IP in /root/.ssh/known_hosts:4 Matching host key in /root/.ssh/known_hosts:5 Are you sure you want to continue connecting (yes/no)? no Host key verification failed. enter code here 

在服务器AI上做到这一点

 eval `ssh-agent -s` ssh-keyscan 107.170.xxx.xxx | tee -a /root/.ssh/known_hosts 

然后我试着ssh。 哇..两个服务器事件有相同的酒吧和私人钥匙。 我正在尝试在服务器之间设置无密码validation。

看来你的一些主机最近改变了IP,并且在IP改变之前和之后你已经连接了它们。

我build议你清理第4行和第5行中的known_hosts文件以摆脱此错误消息。

另一个需要考虑的事情是:如果你只想让服务器A连接到服务器B,你只需要在服务器B的/root/.ssh/authorized_keys中放置服务器公钥(id_dsa.pub或id_rsa.pub的内容)。

如果你想要双向连接,你应该对服务器B进行相同的操作。

从ssh_config(5)手册页,有一个PATTERNS

CheckHostIP

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

所以,你可以在你的/ etc / ssh / ssh_config文件中放入CheckHostIP no


正如@ VinciciusFerrão所说,这是不安全的。 最好的想法是把你的〜/ .ssh / config文件中的CheckHostIP否。有一个示例:

 Host bar.local bar Hostname bar.local CheckHostIP no 

你应该对A和B进行相同的操作,认为使用DHCP的networking是一个好主意。

我们通过删除know_hosts文件中的旧条目来解决类似的问题。