Remove SSH host keys from known_hosts file

As a nwetwork admin you have to replace hardware because it’s faulty or of old age. After replacing the hardware , you will be warned of a man-in-the-middle attack while gaining access using SSH.

Warning looks like:

$ ssh some-host
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:<super long, ECDSA finger print here>.
Please contact your system administrator.

When you are sure that the man-in-the-middle warning is caused by hardware replacement proceed by removing the old ssh key. If you are NOT sure DO NOT proceed and find the root-cause of this warning.

Proceed by removing the old key using the following command;

ssh-keygen -R <hostname>

Now you can get access using SSH. But first you will be prompted to add a new ssh-key to your known-hosts file.

This entry was posted in Uncategorized. Bookmark the permalink.