更换主机后SSH无法登录的问题

 

之前通过SSH远程一台机器(起个名字:cc),某一天把cc重装了一下系统,再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 a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
1e:10:25:81:de:bc:74:92:08:51:ff:ab:49:8d:69:39.
Please contact your system administrator.
Add correct host key in /home/username/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/username/.ssh/known_hosts:6
  remove with: ssh-keygen -f "/home/username/.ssh/known_hosts" -R ***.***.***.
ECDSA host key for ***.***.***.*** has changed and you have requested strict checking.***
Host key verification failed.
复制代码

当client通过ssh连接server时,会把server的信息保存在自己家目录下的.ssh/known_hosts文件里。如果server被重装或者被替换(IP没变),server的信息肯定就改变了,与之前known_hosts里的信息不一致,从而导致密钥认证失败。

解决方法也很简单,根据上面的提示信息,server的信息在/home/username/.ssh/known_hosts:6,直接把known_hosts里server的信息删掉即可。命令也给出来了:

ssh-keygen -f "/username/username/.ssh/known_hosts" -R ***.***.***.

(该命令会生成known_hosts.old,即原文件的备份)。

再次连接时就会给出主机新的ECDSA key。

posted @ 2018-11-06 14:31  anobscureretreat  阅读(356)  评论(0编辑  收藏  举报