欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux 报错:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!(成功解决!)

程序员文章站 2022-07-10 11:16:27
...

1. 问题:ssh 连接服务器出现以下报错

(base) Robin-macbook-pro:~ robin$  ssh aaa@qq.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:IIFv8zvHN4axw3d3WOmTZ6UtzqY1e8JYD0xGlmRehY8.
Please contact your system administrator.
Add correct host key in /Users/robin/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/robin/.ssh/known_hosts:2
ECDSA host key for 192.168.21.212 has changed and you have requested strict checking.
Host key verification failed.

2. 原因:服务器重新安装系统

第一次使用SSH连接时,会生成一个认证,储存在客户端的known_hosts中。

可使用以下指令查看:ssh-****** -l -f ~/.ssh/known_hosts

由于服务器重新安装系统了,所以会出错。

此报错是由于远程的主机的公钥发生了变化导致的。
ssh服务是通过公钥和私钥来进行连接的,它会把每个曾经访问过计算机或服务器的公钥(public key),记录在~/.ssh/known_hosts 中,当下次访问曾经访问过的计算机或服务器时,ssh就会核对公钥,如果和上次记录的不同,OpenSSH会发出警告。

3. 解决:清除连接

使用命令清除所连接的IP:ssh-****** -R 服务器端的ip地址

重新连线,出现以下提示:

linux 报错:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!(成功解决!)
输入yes确认即可连线成功。

输入密码后的确是登陆成功了,但是不一会就断了:

linux 报错:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!(成功解决!)
一下子就自动断开了:

aaa@qq.com:~$ packet_write_wait: Connection to 192.168.21.212 port 22: Broken pipe
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:aXtiQYKlJauqeoKilM+ZzMd1rTkSCN2PHh7QY6Plqh0.
Please contact your system administrator.
Add correct host key in /Users/robin/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/robin/.ssh/known_hosts:2
ECDSA host key for 192.168.21.212 has changed and you have requested strict checking.
Host key verification failed.

4. 再次解决:删除公钥

根据提示:Add correct host key in /Users/robin/.ssh/known_hosts to get rid of this message.
将known_hosts文件中的与登录错误的IP的公钥删除:

  • 进入:vim /Users/robin/.ssh/known_hosts
  • 删掉对应的那条公钥
  • 重新连接和登陆

linux 报错:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!(成功解决!)

  • 成功登陆!

参考:

  1. REMOTE HOST IDENTIFICATION HAS CHANGED问题解决
  2. Linux使用ssh远程连接服务器异常修复
相关标签: Linux/Mac