如何在Linux中修复ECDSA主机密钥警告错误

时间:2020-03-21 11:43:50  来源:igfitidea点击:

多年来,我一直在使用Oracle VirtualBox进行测试和学习目的的许多虚拟机。
前一天,我试图通过ssh连接到一个与Arch Linux运行的远程服务器之一:

$ssh Hyman@theitroad

其中SK是我的远程Arch Linux服务器的用户名,192.168.1.102是Arch Linux IP地址。

运行上面的命令后,我收到了以下警告消息。

<<<<<<<<<<<<<<<<<<<@@
@ 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:UX/eJ3HZT9q6lzAN8mxf+KKAo2wmCVWblzXwY8qxqZY.
Please contact your system administrator.
Add correct host key in /home/sk/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/sk/.ssh/known_hosts:4
ECDSA host key for 192.168.1.102 has changed and you have requested strict checking.
Host key verification failed.

我不能SSHArch Linux系统。
我试图使用替代用户名登录,但我得到了相同的结果,如上所示。

这实际上不是错误消息。
它只是一个安全通知,指示给定远程系统的ECDSA主机密钥自上次连接以来已更改。
正如我们所知道的,当我们通过SSH首次访问远程系统时,通过SSH从本地系统访问该远程主机发送的ECDSA密钥的指纹,并在本地中缓存并存储在$home/.ssh/neark_hosts文件中系统。

重新安装远程系统或者为多个远程系统分配相同的IP地址后,身份(指纹)发生变化时,上述警告消息显示。

在Linux中修复ECDSA主机密钥警告错误

要解决此问题,首先我们需要在本地系统的已知_hosts文件中更新远程系统的缓存ECDSA主机密钥。
我们可能知道,通常,主机密钥将存储在/home/yourusername/.ssh/known_hosts文件中。

要删除缓存密钥,请使用以下命令:

$ssh-keygen -R <remote-system-ip-address>

在我们的情况下,远程系统的IP是192.168.1.102,因此让我们使用以下命令从"已知_Hosts"文件中删除主机密钥。

$ssh-keygen -R 192.168.1.102

示例输出:

# Host 192.168.1.102 found: line 4
/home/sk/.ssh/known_hosts updated.
Original contents retained as /home/sk/.ssh/known_hosts.old

完毕!

现在,再次尝试使用命令SSH到远程系统:

$ssh Hyman@theitroad102

键入"是"并按ENTER键以在本地系统的已知_HOSTS文件中更新远程系统的主机密钥。

The authenticity of host '192.168.1.102 (192.168.1.102)' can't be established.
ECDSA key fingerprint is SHA256:UX/eJ3HZT9q6lzAN8mxf+KKAo2wmCVWblzXwY8qxqZY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.102' (ECDSA) to the list of known hosts.
Hyman@theitroad's password: 
Last login: Thu Jan 19 18:01:24 2015
[Hyman@theitroad ~]$