共计 1831 个字符,预计需要花费 5 分钟才能阅读完成。
之前通过 SSH 远程一台机器(起个名字:linuxidc),某一天把 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。
感兴趣的可以看看 SSH 的原理
下面关于 SSH 相关的文章您也可能喜欢,不妨参考下:
Ubuntu 下配置 SSH 服务全过程及问题解决 http://www.linuxidc.com/Linux/2011-09/42775.htm
Ubuntu 14.04 下安装 Samba 及 SSH 服务端的方法 http://www.linuxidc.com/Linux/2015-01/111971.htm
SSH 服务远程访问 Linux 服务器登陆慢 http://www.linuxidc.com/Linux/2011-08/39742.htm
提高 Ubuntu 的 SSH 登陆认证速度的办法 http://www.linuxidc.com/Linux/2014-09/106810.htm
开启 SSH 服务让 Android 手机远程访问 Ubuntu 14.04 http://www.linuxidc.com/Linux/2014-09/106809.htm
如何为 Linux 系统中的 SSH 添加双重认证 http://www.linuxidc.com/Linux/2014-08/105998.htm
在 Linux 中为非 SSH 用户配置 SFTP 环境 http://www.linuxidc.com/Linux/2014-08/105865.htm
Linux 上 SSH 服务的配置和管理 http://www.linuxidc.com/Linux/2014-06/103627.htm
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-04/129849.htm