2025-08-06
00
请注意,本文编写于 136 天前,最后修改于 136 天前,其中某些信息可能已经过时。

目录

1. 情景描述
2. 解决
1. 报错含义
2. 常见原因
3. 解决方法:用文本编辑器打开并手动删除对应行

1. 情景描述

 电脑首次通过终端成功连接Linux设备后;更换设备,但IP不变,进行终端连接时产生如下报错:

bash
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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:83EVp2xxxxxxxq2T1673aikbbi2Gh4sxxxxxxxxxx. Please contact your system administrator. Add correct host key in /Users/xxxx/.ssh/known_hosts to get rid of this message. Offending ECDSA key in /Users/xxxx/.ssh/known_hosts:13 Host key for [192.168.55.78]:3719 has changed and you have requested strict checking. Host key verification failed.

2. 解决

1. 报错含义

bash
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 我的 ~/.ssh/known_hosts 文件中,记录了 IP 192.168.55.78(端口 3719)的旧的公钥 fingerprint(指纹),但目标主机现在给你发送了一个新的公钥,因此 SSH 报出警告,担心是被篡改或中间人攻击。

bash
The fingerprint for the ECDSA key sent by the remote host is SHA256:83EVp2xxxxxxxq2T1673aikbbi2Gh4sxxxxxxxxxx. Add correct host key in /Users/xxxx/.ssh/known_hosts to get rid of this message. Offending ECDSA key in /Users/xxxx/.ssh/known_hosts:13 Host key for [192.168.55.78]:3719 has changed and you have requested strict checking. Host key verification failed.
  • known_hosts:13 表示这个主机的旧密钥在你本地 known_hosts 文件的第 13 行
  • fingerprint 是远程服务器发来的公钥指纹
  • SSH 默认开启了 StrictHostKeyChecking,所以不允许自动接受新的 key

2. 常见原因

原因说明
目标主机重装过系统或 SSH 服务公钥会变
主机更换了密钥对也会导致 key 改变
本地连接过另一个不同的机器使用了相同的 IP(但其实不是同一主机)会误判为 key 被篡改
网络被劫持,可能是中间人攻击(MITM)极少见,但是 SSH 报警的目的

3. 解决方法:用文本编辑器打开并手动删除对应行

bash
nano ~/.ssh/known_hosts

 执行后会自动从 ~/.ssh/known_hosts 中删除对应行。然后再次连接:

bash
ssh -p 3719 [username]@192.168.55.78

 你会看到提示:

bash
Are you sure you want to continue connecting (yes/no/[fingerprint])?

 输入 yes 后会将新的 key 加入到 known_hosts 文件中。

本文作者:精卫

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!