2011
25
Jan

How to Fix RSA Host Key Change Error on Mac

At work recently, we wiped a Fedora development server and reinstalled with the newer version of the OS. When everything was back up and running, I tried to connect to it through SSH. I got an error I hadn’t seen before about my RSA host key is wrong.

First of all, the error I was getting is below:

This was actually pretty easy to fix. Since you are already trying to SSH, this assumes you already know where Terminal is and you have it opened:

1) Inside Terminal, type
cd /Users/YOUR_USERNAME/.ssh
Where YOUR_USERNAME is your login name for your Mac. If you don’t what what it is, your login name is the word right before the $ in the Terminal window.

2) Inside Terminal again, type
rm known_hosts

That’s it. Your done. You can now go through SSH again. A new RSA key will be generated for you automatically. All this really did was delete a file named known_hosts inside the hidden /Users/YOUR_USERNAME/.ssh directory. Since it deleted the file, this also means that RSA keys for other SSH connections will be lost as well. However the next time you SSH to them, you will be given a new key automatically.

7 Responses to How to Fix RSA Host Key Change Error on Mac

  1. If you ssh to a lot of servers running rm on the known_hosts file will mean you have to accept the hosts key on all your servers again.

    In the screenshot above you can see the line:

    Offending key in /Users/username/.ssh/known_hosts:6

    Basically this shows the offending key is on line 6 so

    vi /Users/username/.ssh/known_hosts:6

    :6

    dd

    :wq

    Open the file with vi
    Shortcut to line 6
    Remove line 6
    Write and quite vi

    You get quite good at this when making OS templates and testing them…

  2. Jess says:

    I cant thank you enough for this quick fix tried to sift through some other people’s descriptions and really confusing.

  3. anon says:

    Thank you!

  4. David says:

    Awesome! Been learning Linux and Mac and this was a huge help!

  5. Brian says:

    Thank you thank you thank you!! This was driving me crazy after a server rebuild and I couldn’t connect to any of my stored SFTP accounts in my editor program.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>