Linux: SSH报错 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 解决方案, Remove key from known_hosts, Fix Offending key in ~/.ssh/known_hosts file

 

今天是用google cloud ssh登录的时候,发生以下报错:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
5c:9b:16:56:a6:cd:11:10:3a:cd:1b:a2:91:cd:e5:1c.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:1
RSA host key for ras.mydomain.com has changed and you have requested strict checking.
Host key verification failed.
Linux: SSH报错 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 解决方案, Remove key from known_hosts, Fix Offending key in ~/.ssh/known_hosts file
Linux: SSH报错 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 解决方案, Remove key from known_hosts, Fix Offending key in ~/.ssh/known_hosts file

网上一大堆解决方案都是:

ssh-keygen -R "hostname OR ip address"

应该可以解决问他,但是我这里行不通,可能原因是我把 ~/.ssh/known_hosts 文件给删除了!

所以,我的解决方法也很简单,根据上面的提示:

Offending key in /home/user/.ssh/known_hosts:1

那么我就执行下面的命令:

sed -i '1d' /home/user/.ssh/known_hosts

即:删除文件内 /home/user/.ssh/known_host 的第一行

正如我上面说的,因为我把 ~/.ssh/known_hosts 文件给删除了,所以,我的真实报错是:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:iS3kySidcxMXYYCnuo3mxDuuIJ/IJ77AM+tuhA5wnSY.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:9
  remove with:
  ssh-keygen -f "/root/.ssh/known_hosts" -R 35.103.140.135
ECDSA host key for 35.103.140.135 has changed and you have requested strict checking.
Host key verification failed.

不过没有关系,知道原理就行,根据提示 Offending ECDSA key in /root/.ssh/known_hosts:9 ,删除路径中的第九行:

sudo sed -i '9d' /root/.ssh/known_hosts

 

完毕!

 

 

本文:Linux: SSH报错 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! 解决方案, Remove key from known_hosts, Fix Offending key in ~/.ssh/known_hosts file

Leave a Reply