Remove IP from known hosts via command line

If you ever get the following test or similar:-

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:+gR9POhmCViodxkWtJlwAzv/6bPHSB0sQmaVygRrAYw.
Please contact your system administrator.
Add correct host key in /home/user/.ssh/known_hosts to get rid of this message

It’s probably because you’ve reinstalled a machine, but with modern key hashes which line do you remove?

Well if you know the IP address or hostname you can remove it from known hosts like this

ssh-keygen -f "/home/user/.ssh/known_hosts" -R 174.131.214.120

You can attempt to connect again and add the server back to your known hosts.

Author: Andrew

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.