How to remove a host key from ssh known_hosts file?

Have you ever run into an issue as shown below when you try to SSH or maybe scp a file to a different remote machine?

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:5nty4H8NgVJBx2+TBlCrgFNaaKdcQ6sNLo9HfUIZTFo.
Please contact your system administrator.
Add correct host key in /Users/mukul.manikandan/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/mukul.manikandan/.ssh/known_hosts:14
ECDSA host key for 10.10.10.62 has changed and you have requested strict checking.
Host key verification failed.

This usually happens when you re-use IP addresses and assign them to a different machine that has a unique SHA fingerprint. The solution for this is to simply remove the host entry from your machines known_hosts file so that the new entry can be added, and this can be achieved with the following ssh-keygen command:

ssh-keygen -R <hostname>

Once this is done, retry the task you were trying earlier, and you should be good! Hope this helps! ☺️

Previous
Previous

How to run a Docker container using privileged access?

Next
Next

How to identify your postgres data directory?