尝试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.
Run Code Online (Sandbox Code Playgroud)
我知道为什么,因为我更改了此类服务器的 ip。但如果不是这样,我如何检查远程主机发送的 ECDSA 密钥的指纹?
我尝试通过以下方式这样做:
echo -n ipofthehost | sha256sum
Run Code Online (Sandbox Code Playgroud)
但我没有得到相同的指纹。我也尝试过类似AWS 中的“hostname,ip” ,但没有得到任何匹配。
如果我从我的 known_hosts 文件中删除入口并ssh
再次尝试,它会成功并告诉以下内容:
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx/xxxxxxx.
Are you sure you want to continue connecting (yes/no)?
Run Code Online (Sandbox Code Playgroud)
那么什么是应用 sha256sum 来获取指纹以及我如何检查它?
Xav*_*cas 19
公钥指纹不是 IP 地址字符串的简单哈希。
要检索远程主机公钥,您可以使用ssh-keyscan <IP address>
,然后您可以使用常用工具提取其指纹 ( ssh-keygen -lf <public_key_file>
)。
最后,您可以将known_hosts
文件中的当前指纹与ssh-keygen -l -F <domain_or_IP_address>
.
Wat*_*ker 10
更详细一点:因为警告消息是指远程主机发送的ECDSA密钥的指纹,所以我们收集有关主机的公共 (ECDSA) 密钥的信息:
ssh-keyscan -t ecdsa <IP_address_or_hostname> ECDSA_file_to_compare
Run Code Online (Sandbox Code Playgroud)
然后我们可以在known_hosts文件中找出公共 (ECDSA) 密钥的位置:
ssh-keygen -l -F ipofhost
Run Code Online (Sandbox Code Playgroud)
如果我们要比较指纹,我们必须将其放入known_hosts文件的内容中(仅与该主机相关的条目)。我们可以称其为 ecdsa_file_from_known_hosts,然后将它们进行如下比较:
ssh-keygen -lf ecdsa_file_to_compare
ssh-keygen -lf ecdsa_file_from_known_hosts
Run Code Online (Sandbox Code Playgroud)
并检查它们是否显示相同的哈希值。
当然它们不匹配,这就是我收到警告消息的原因(ssh
内部检查此匹配)。如果我们确定 IP 地址更改(因此我们没有遭受中间人攻击),我们可以删除该主机在我们known_hosts文件中的条目,下次我们ssh
进入它时,一个新的条目因为它将被添加到这样的文件中。
归档时间: |
|
查看次数: |
76732 次 |
最近记录: |