Fork me on GitHub

ssh 登陆遇到 Host key verification failed

ssh 登陆时,遇到 host key verifycation failed 的情况

1
2
3
4
5
6
7
8
9
10
11
12
13
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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:MU0btYHPprmjRMfcs6mtciH407u1hCJzz71wG7EuUUE.
Please contact your system administrator.
Add correct host key in /Users/banshee/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/banshee/.ssh/known_hosts:12
ECDSA host key for [xxx.xxx.xxx.xx]:xxxx has changed and you have requested strict checking.
Host key verification failed.

出现这种情况的原因是,第一次 SSH 连接服务器时,会生成一个公钥,存储在客户端的 known_ host 文件里。而我的服务器重装了系统,生成了新的公钥,而客户端known_hsot 里还保存着旧的公钥。所以会出现以上错误。

解决方式也很简单:

  • 使用命令
    1
    ssh-keygen -R xx.xx.xx.xx:pp(IP:PORT)

或者直接vim 进去删除服务器IP对应的记录。
再次连接,会出现接受服务器公钥的询问,输入 yes 即可。