Problem:
A server which I regularly used to connect to using SSH one day gave me the following error:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
4e:90:89:55:75:44:ca:65:fa:b6:e6:78:24:cb:99:83.
Please contact your system administrator.
Add correct host key in /users/prakash/.ssh/known_hosts to get rid of this message.
Offending key in /users/prakash/.ssh/known_hosts:1
RSA host key for ServerName has changed and you have requested strict checking.
Host key verification failed.
Couldn’t read packet: Connection reset by peer
Reason:
The reason is stated in the warning itself. The public key of the server has been changed either by the server itself or some malicious user for a man in the middle attack. You remember the first time you connect to a server through SSH it asks whether or not to store the store the key to your known hosts. In this case, the key to the server has already been saved into known hosts but that key is now changed and thus we have a conflict here.
Solution:
Solution is pretty much straight forward. If you trust on the server and believe that the key has been changed officially then you can again add the new key to the known hosts.
- To do this go to the hidden .ssh directory (mostly in your home directory: cd ~).
- Open the file known_hosts.
- Edit the file. Delete the line containing ServerName (the server name specified in the warning).
- Now try to connect to the server manually i.e.
ssh username@servername. - It will ask again to add the new key to known hosts. Add it.
Hope that solves your problem with SSH. Enjoy secure connections. Questions and suggestions are most welcomed. If you liked the post, do subscribe to keep in touch.