SSH RSA host key has just been changed


When a domain has been moved from one server to another or a machine has been formatted, issue with SSH login occurs. The warning dialog that most SSH programs give looks something like this:
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 /home/user/.ssh/known_hosts to get rid of this message.
Offending key in /home/user/.ssh/known_hosts:4
RSA host key for has changed and you have requested strict checking.
Host key verification failed.
The SSH program will print this message and often exit, prohibiting the user from connecting to the remote machine.
This problem arises when a site has changed servers, and the new server RSA key which is transmitted when authenticating is different from the old server
when a linux box is formatted it creates a new set of RSA keys for ssh authentication. Since old RSA key is stored in your known_host file when you last ssh to the remote machine, ssh will not let you login to that machine till you save the correct new RSA key. You can do it in 2 ways:


In the case of a migration, you can be reasonably sure that the RSA key change is not an accident, but to connect to the new server you must remove the line in .ssh/known_hosts that corresponds to your domain name. This can be done by editing ‘known_hosts’ by hand or if your machine has Perl installed you can use this one liner:
perl -p -i -e 's/^*n//;' ~/.ssh/known_hosts
Substitute your actual domain for making sure to include a backslash before the dot. If you have several domains that have moved you must repeat this step for each one.
You can simply delete the RSA key which is stored against the IP of remote machine to which you are doing SSH from your /yourhome/.ssh/known_hosts file.
Afer this restart the SSH service and you are done.
# service sshd restart

About Manish Jha

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Linux/CentOS, SSH. Bookmark the permalink.

21 Responses to SSH RSA host key has just been changed

  1. blogg.Asia says:

    Thanks for sharing your thoughts about lifelong. Regards


  2. Hier Klicken says:

    Unquestionably imagine that that you stated. Your favourite reason appeared to be at
    the net the simplest thing to take into account
    of. I say to you, I definitely get irked while folks think about issues that they plainly don’t recognise about.
    You managed to hit the nail upon the highest and also defined out the entire thing
    without having side effect , folks can take a signal. Will likely be back
    to get more. Thanks


  3. Santosh Kumar says:

    Manually Editing
    vi ~/.ssh/known_hosts

    #Removing the confilcting host key

    and remove


  4. It’s remarkable in favor of me to have a website, which is useful for my know-how.

    thanks admin


  5. I will right away take hold of your rss as I can’t in finding your email subscription link or
    newsletter service. Do you’ve any? Please allow me know so that I may subscribe.


  6. I have been browsing online more than 3 hours lately, yet I by no means found any fascinating article like yours.
    It is pretty price sufficient for me. Personally, if all webmasters and bloggers made excellent content as you did, the
    net will be much more helpful than ever before.


  7. I enjoy what you guys are up too. This sort of clever work
    and exposure! Keep up the good works guys I’ve incorporated you
    guys to blogroll.


  8. social media says:

    If some one wishes to be updated with newest technologies
    then he must be go to see this website and be up to date every day.


  9. Carolina says:

    Hi there, I enjoy reading all of your article.
    I like to write a little comment to support you.


  10. Maria says:

    This piece of writing will assist the internet users
    for setting up new weblog or even a weblog from start to


  11. you are in reality a just right webmaster. The web site loading velocity is incredible.
    It seems that you are doing any unique trick. Furthermore, The contents are masterwork.
    you’ve done a fantastic activity in this matter!


  12. website says:

    I’ve read some just right stuff here. Definitely
    value bookmarking for revisiting. I surprise how so much attempt you put to create
    such a excellent informative site.


  13. alexhunt says:

    thanks website.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s