linux重装系统后ssh 登录失败
前段时间买了一台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 ECDSA key sent by the remote host is
SHA256:kIBiWLcDm7llv9KqOy/XjDQKGOtupTOCwpAbPybDY8g.
Please contact your system administrator.
Add correct host key in /Users/user/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/user/.ssh/known_hosts:11
ECDSA host key for x.x.x.x has changed and you have requested strict checking.
Host key verification failed.
当client通过ssh 连接server时,会把server的信息保存在自己的家目录下,(~/.ssh/known_hosts),如果server被重装,server的信息肯定就改变了(但是ip并未发生改变),与之前known_hosts里的信息不一致,从而导致密钥认证失败。
解决方法如下:根据提示信息,server的信息在/Users/user/.ssh/known_hosts:11,直接把known_hosts里server的信息删掉即可。
即类似这个key信息:11.11.11.34 ssh-rsa AAAAB3NzakjfksfhHIHhlQEA0Whm0wOOL7eN0XHfHd7NDl6JwUJbtat2V4sYaU4tW0TiuZEOyIeoX7dfpQS2sMtIMkt4u56St+zCLqncNO24pr6YlxNmLGs8/a/2gff+6cAiDqOFP+kbZycIatgZaVLlCm2jjz2J61CClC9g3WK9xXpRoDuynwB2WYo5Uc6kptsAresbCpKZnok8YTsNC9stXYn5Pfxt3jFssT9iIX30lOtrJNDoU5oZZ2oLKX5DHMoGzzoz2Nhr8hdFkTHbA6xa0VwKDI2T7CphzNZxcxlVihTcxUWZZYbyOiA0RGE9NIpsezVNWLi0m5Zz8lcdAylxo6JtP/Mav7/6wOnVQk9Ovw==
删除之后,尝试重新连接server,会提示
The authenticity of host ‘111.11.11.111 (111.11.11.111)’ can’t be established.
ECDSA key fingerprint is SHA256:kIBiWLcDm7llv9KqOy/XjDQKGOtupTOCwpAbPybDY8g.
Are you sure you want to continue connecting (yes/no)?
输入yes,server与本地重新建立对应关系,这时/Users/user/.ssh/known_hosts又生成了新的key
之后你就可以正常使用server了
亲测有效