≡ Menu

Mac OS X Remove SSH Known Host

I‘ve reinstalled Linux on remote server and now trying to connect it over ssh using Mac OS X:
ssh user@server1.example.com

But I’m getting an error which read as follows:

Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /Users/user/.ssh/known_hosts to get rid of this message.
Offending key in /Users/user/.ssh/known_hosts:1
RSA host key for server1.example.com has changed and you have requested strict checking.
Host key verification failed.

How do I fix this problem under Mac OX X?

You need to run the following command to get rid of this problem. Open the terminal and type the following command:

ssh-keygen -R server-name
ssh-keygen -R server.ip.addre.ss
ssh-keygen -R
ssh-keygen -R server1.example.com
Fig.01: Removing /Users/user/.ssh/known_hosts file

Fig.01: Removing /Users/user/.ssh/known_hosts file

Now you can connect to remote host with ssh:

ssh user@server1.example.com
Share this tutorial on:
{ 12 comments… add one }
  • Chichi LattéApril 11, 2012, 1:05 pm

    Much appreciated Vivek, this worked for me no probs!

  • Bike JerryDecember 30, 2012, 4:45 pm

    This helped me out as well – thank you, happy new year!

  • CraigMay 28, 2013, 8:26 am

    Didn’t work for me, showed exactly what you said it would but when I try to SSH in it continues to show the original message… :-(

  • IanJuly 21, 2013, 11:29 am

    Thanks for this. Had two ftp sites that Coda refused to connect to, but Cyberduck was happy with.

  • HugoAugust 28, 2014, 3:44 am

    Worked great! Thank you!!

  • CyrilSeptember 12, 2014, 9:36 pm

    I was having the same problem as I was setting up a lots of routers with the same IP over ssh. What worked for me was to remove known_hosts file which is stored in ~/.ssh/knonw_host. So what I did was updating my /etc/bashrc file with the following lines:

    rm ~/.ssh/known_hosts

    Than when this message appeared I simply typed rmknownhosts and delete the file.

    I don`t know if this is right step to deal with that. But it definitely worked for me.

    Hope that helps.

  • LouSeptember 14, 2014, 6:01 am

    Worked for me… I just needed to clear the 1 entry of “[myserver].com”
    ssh-keygen -R [myserver].com

  • BogdanNovember 20, 2014, 10:24 am

    Great, exactly what I needed quick and simple. Thank you!

  • JamesMay 27, 2015, 3:58 pm

    Unfortunately I don’t think this command actually did anything.

  • JanJuly 17, 2015, 4:28 pm


  • SaiAugust 20, 2015, 5:50 pm

    It worked by using the following commands:

    cd /Users/Username/.ssh/Known_hosts
    ssh-keygen -R domain-name
    ssh-keygen -R server


  • SueMay 16, 2016, 11:22 pm

    You saved me today. Thanks, it worked for me under a complicated situation. Thanks.

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , ,