Fixing “Remote Host Identification Has Changed” Error When SSH to a Server

If you encounter an error message like the one below when attempting to SSH to a server:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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.

This issue typically arises because the server’s public key has changed. To resolve this problem, you can remove the existing record of the server’s public key and allow it to be re-downloaded.

Follow these steps to fix the error:

First, run the following command to remove the existing public key record for the server:

ssh-keygen -R <server_domain>

Replace <server_domain> with the domain of the server you are trying to connect to, such as gpu1.example.com.

Once the old public key record has been removed, try connecting to the server again using SSH. The server’s new public key will be automatically downloaded and added to your known hosts file.

Please note that if you still encounter issues or suspect a man-in-the-middle attack, you should contact your system administrator for further assistance.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *