ssh无法登录linux服务器的解决办法

最近之前使用的一台linux服务器被长官重装系统了,导致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 RSA key sent by the remote host is
SHA256:az7FfVtBpsebsnnIN5nAyqBzE3oEmTYcTd/bJu+yp38.
Please contact your system administrator.
Add correct host key in /home/kaixi_fan/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/kaixi_fan/.ssh/known_hosts:2
RSA host key for 172.29.38.37 has changed and you have requested strict checking.
Host key verification failed.

看起来是ssh key我本地终端和服务器保存的,2者对不上了,这时候可以这么办:
删除提示信息中,对应的行数,例如上例,需要删除 /home/kaixi_fan/.ssh/known_hosts文件的第2行。

然后重新登录,会给出如下提示:

The authenticity of host '172.29.38.37 (172.29.38.37)' can't be established.
ECDSA key fingerprint is xxxxxxxxxxxxxxxxxxxxxxxxxx(此处是key)
Are you sure you want to continue connecting (yes/no)? yes(输入yes)
Warning: Permanently added '172.29.38.37' (ECDSA) to the list of known hosts.

重新输入yes就好啦。

原文地址:https://www.cnblogs.com/ironx/p/5238820.html