在试图将ssh插入服务器时,我收到了一条众所周知的警告消息:
$ ssh whateverhost
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx/xxxxxxx.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/user/.ssh/known_hosts:10
ECDSA host key for ipofmyhost has changed and you have requested strict checking.
Host key verification failed.我知道为什么,因为我改变了这样的服务器的ip。但是如果不是这样的话,我如何检查远程主机发送的ECDSA密钥的指纹呢?
我试图这样做:
echo -n ipofthehost | sha256sum但我没有同样的指纹。我也尝试了“主机名,ip”,有点像在AWS,但我没有得到任何匹配。
如果我从我的known_hosts文件中删除入口并再次尝试ssh,它成功并告诉如下:
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx/xxxxxxx.
Are you sure you want to continue connecting (yes/no)?那么,它是如何应用sha256sum来获取指纹的,以及我如何检查它呢?
发布于 2015-05-09 21:07:56
公钥指纹不是IP地址字符串的简单散列。
要检索远程主机公钥,可以使用ssh-keyscan <IP address>,然后可以使用常用工具提取其指纹(ssh-keygen -lf <public_key_file>)。
最后,您可以将known_hosts文件中的当前指纹与ssh-keygen -l -F <domain_or_IP_address>进行比较。
发布于 2015-05-11 09:28:33
更详细一些:因为警告消息是指远程主机发送的ECDSA密钥的指纹,所以我们收集主机的公共密钥(ECDSA)的信息:
ssh-keyscan -t ecdsa <IP_address_or_hostname> ECDSA_file_to_compare然后,我们可以发现在我们的known_hosts文件中,public (ECDSA)的关键是什么地方:
ssh-keygen -l -F ipofhost如果我们想比较指纹,我们必须把我们的known_hosts文件的内容(只是与这个主机相关的条目)。我们可以将其称为ecdsa_file_from_known_hosts,然后按以下方式对它们进行比较:
ssh-keygen -lf ecdsa_file_to_compare
ssh-keygen -lf ecdsa_file_from_known_hosts看看他们是否显示了相同的哈希。
当然,它们不匹配,这就是为什么我收到警告消息(ssh在内部检查此匹配)。如果我们确信IP地址的变化(所以我们不会遭受中间人攻击),我们就可以删除known_hosts文件中的主机条目,下一次当我们ssh进入该文件时,将向这样的文件中添加一个新条目。
https://serverfault.com/questions/690855
复制相似问题