SSH – how to remove offending ssh key from known_hosts file

So  I have demoted and removed my old CentOS server that was myrsync server. New server has been installed and configured and I am trying to run my rsync over SSH and getting this error message about possible a Man-in-the-Middle Attack and mismatch of ssh keys. Of course, I have changed name but kept same IP address for the new server. My other server is keeping the old ssh keys in known_host file and now when connecting – they do not match :-).  You do not want to delete the entire known_hosts file and as well you do not want to disable this feature. It is very important feature so it gives you warning if really Man in the Middle attack is taking place. There is easy fix for this problem 😉

[nggallery id=20]

Here is how to remove the the offending key. Once you remove the key, you will be prompted again first time before you connect over ssh to add the new detected keys and IP into your known_host file.

### to see the keys in output (my case)
cat /root/ .ssh/known_hosts

Here is command line to remove my offending key for IP:

ssh-keygen -R

Now the offending and mismatched key is removed and you can reconnect again with ssh and you will be able to add and update your known_host file with the new and correct ssh key for the system 🙂

Leave a Reply

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