Warning: Remote Host Identification Has Changed error and solution

by Vivek Gite on September 28, 2006 · 38 comments

When I run ssh command I get an error which read as follows:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
5c:9b:16:56:a6:cd:11:10:3a:cd:1b:a2:91:cd:e5:1c.
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:1
RSA host key for ras.mydomain.com has changed and you have requested strict checking.
Host key verification failed.

How do I get rid of this message?

If you have reinstalled Linux or UNIX with OpenSSH, you will get the above error. To get rid of this problem:

Solution #1: Remove keys

Use the -R option to removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts. If your remote hostname is server.example.com, enter:
$ ssh-keygen -R {server.name.com}
$ ssh-keygen -R {ssh.server.ip.address}
$ ssh-keygen -R server.example.com

Sample output:

/home/vivek/.ssh/known_hosts updated.
Original contents retained as /home/vivek/.ssh/known_hosts.old

Now, you can connect to the host without a problem.

Solution #2: Add correct host key in /home/user/.ssh/known_hosts

It is not necessary to delete the entire known_hosts file, just the offending line in that file. For example if you have 3 server as follows.
myserver1.com,64.2.5.111 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA11FV0EnGahT2EK8qElocjuHTsu1jaCfxkyIgBTlxlrOIRchb2pw8IzJLOs2bcuYYfa8nSXGEcWyaFD1ifUjfHelj94AAAAB3NzaC1yc2EAAAABIwAAAIEA11FV0E
nGahT2EK8qElocjuHTsu1jaCfxkyIgBTlxlrOIRchb2pw8IzJLOs2bcuYYfa8nSXGEcWyaFD1ifUjfHelj94H+uv304/ZDz6xZb9ZWsdm+264qReImZzruAKxnwTo4dcHkgKXKHeefnBKyEvvp/2ExMV9WT5DVe1viVwk=
myserver2.com,125.1.12.5 ssh-rsa
AAAAB3NzaC1yc2EAAAABIwAAAQEAtDiERucsZzJGx/1kUNIOYhJbczbZHN2Z1gCnTjvO/0mO2R6KiQUP4hOdLppIUc9GNvlp1kGc3w7B9tREH6kghXFiBjrIn6VzUO4uwrnsMbnAnscD5EktgI7fG4ZcNUP 5+J7sa3o+rtmOuiFxCA690DXUJ8nX8yDHaJfzMUTKTGxQz4M/H2P8L2R//qLj5s3ofzNmgSM9lSEhZL/IyI4NxHhhpltYZKW/Qz4M/H2P8L2R//qLj5s3ofzNmgSM9lSEhZL/M7L0vKeTObue1SgAsXADtK3162a/Z6MGnAazIviHBldxtGrFwvEnk82+GznkO3IBZt5vOK2heBnqQBfw=
myserver3.com,125.2.1.15 ssh-rsa
5+J7sa3o+rtmOuiFxCA690DXUJ8nX8yDHaJfzMUTKTGx0lVkphVsvYD5hJzm0eKHv+oUXRT9v+QMIL+um/IyI4NxHhhpltYZKW
as3533dka//sd33433////44632Z6MGnAazIviHBldxtGrFwvEnk82/Qz4M/H2P8L2R//qLj5s3ofzNmgSM9lSEhZL/M7L0vKeTObue1SgAsXADtK3162a/Z6MGnAazIviHBldxtGrFwvEnk82+GznkO3IBZt5vOK2heBnqQBfw==

To delete 2nd server (myserver.com), open file:
# vi +2 .ssh/known_hosts
And hit dd command to delete line. Save and close the file. Or use following
$ vi ~/.ssh/known_hosts
Now go to line # 2, type the following command
:2
Now delete line with dd and exit:
dd
:wq

Solution 3: Just delete the known_hosts file If you have only used one ssh server

$ cd
$ rm .ssh/known_hosts
$ ssh ras.mydomain.com

Now you should be able to connect your server via ssh.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 38 comments… read them below or add one }

1 Chris Kolosiwsky October 5, 2006

It’s not necessary to delete the entire known_hosts file, just the offending line in that file.

Using your example, all you need to do is:

vi ~/.ssh/known_hosts
1G
dd
:wq

And done. This is helpful if you manage a large group of servers and have *many* keys cached. If you delete the entire file, you will br prompted to add the server’s key on each connection attempt.

Reply

2 Paul March 9, 2011

I have an easier way to just delete the one offending key:

EXAMPLE: sed -i ’2d’ .ssh/known_hosts

Just replace the 2 in the example above with whatever line it says contains the offending key.

Reply

3 don April 4, 2011

Yes this was the best and easiest solution out of all.

thanks

Reply

4 nixcraft October 5, 2006

Chris,

Good point / tip, if I have 100′s of ssh server; it will be a problem for me.

Appreciate your post.

Reply

5 Amos Shapira November 26, 2007

The right way to do this is with “ssh-keygen -R ip-address”.

–Amos

Reply

6 Paul March 11, 2011

Cool, I’ll try that next time….Thanks Amos!

Reply

7 Log January 23, 2008

Theres actually a script that does this at
http://blog.hacker.dk/2008/01/script-to-fix-ssh-host-identification-changed/

Aparently it doesnt use the sshkeygen, but it does the work nicely and easy:
script

Reply

8 andy February 17, 2008

thanks Amos for the correct way to update rsa host keys.

Reply

9 deepen March 3, 2008

Thanks for nice solution.

The above mentioned problem I face when remote computer completely formated and they give us again ssh connection. And because of RSA digital signature of computer identification the local computer does not accept the remote computer (as I think).

Once again thanks for solution.

Regards,
Deepen

Reply

10 S. Cornall June 20, 2008

Thanks, your solution worked for my SSH login. Currently still can’t log in properly through my ltsp server. It says it is checking the password and then ends the session. I definitely have a link to the server (i.e. and address) Any ideas about this? Thank-you in advance.

Reply

11 eri winandar December 28, 2008

It works fo me :)
vi ~/.ssh/known_hosts
dd
:wq

Reply

12 Soundar March 22, 2011

dd worked for me too, tks.

Reply

13 uttam January 15, 2009

Thanks for the solution

Reply

14 anonymous February 8, 2009

Hi,
I’m getting the same error. I compared the RSA keys in my known_hosts file with the host key of the remote computer….they are the same. I thought I’d find out if it is a genuine MITM attack or not, so I shut down the SSH server on the remote machine and accepted the newly presented key. Connection to the remote machine now yields a “Permission denied” message, since I use public-private key authentication.

Does this mean that I am, in fact, being subjected to a MITM attack?

Thanks.

Reply

15 anonymous February 10, 2009

Above mentioned problem was solved. I restarted the remote machine, and everything started working properly..

Weird….

Reply

16 chaiklang9 February 26, 2009

Thanks. Good job.

Reply

17 carlos March 4, 2009

Thanks….it’s works for my.greetings from argentine!!! bye

Reply

18 Tguntara March 31, 2009

I had same problem.,, i tried to used Amos Sapira suggest.
#ssh-keygen -R ip_that_have_problem

and.. IT WORKS..
thanx a lot guys…
Regard … TGUNTARA

Reply

19 error3 May 17, 2009

just for help :
the port of a ssh wasn’t 22.
I need to ssh-keygen -R [ip]:port
(keep the ‘[‘)

Reply

20 niko June 15, 2009

in my case I had another problem:
I had set the options
UserKnownHostsFile=no
StrictHostKeyChecking=no
in my config and this prevented the new host to be added to known_hosts. I got the error every time I tried to contact the host and never got a prompt to add it to known hosts.

Reply

21 Andrew Abogado July 25, 2009

Big help especially solution number 3. :)
Finally get rid of that error message. Made me really paranoid of the “eavesdropping” thing.

Thanks a lot for the tip.

Reply

22 lucky August 24, 2009

hi, thansk a lot.. solution 3 worked :)

Reply

23 wid get October 7, 2009

got one better for you.

ssh -1 host fails, asking for password, even though pub key is correct on remote host.
subsequent ssh -1 host fails with man-in-the-middle warning. this is an endless cycle.

ssh -2 host works fine from the command line. from the veritas netbackup NBU_include.pl script, that same command fails on auth error.

;-)

Reply

24 Gustavo Serrano February 19, 2010

Thanks, very helpful

Reply

25 Anonymous May 7, 2010

thanks

Reply

26 hoosfoos June 6, 2010

thanks for the solution to this! I used:
vi ~/.ssh/known_hosts
dd
:wq

Reply

27 midou June 8, 2010

thanks for solutions

Reply

28 Unknown November 13, 2010

Thank you for the post, this helped me get back into my ipod 2 gen after I messed up badly by accidentally removing the folder labeled System. You’re awesome!

Reply

29 fs November 21, 2010

Thanks. I never knew about ssh-keygen -r {IP-Address}

Reply

30 K-2 February 26, 2011

Thanks for the solo, quick & painless! Appreciate it!

Reply

31 gameculb2002 March 11, 2011

it’s work for me, tks!

Reply

32 santosh lohar March 15, 2011

Hi guys,

thanks fo rthe solution I have also one query when I am doing vncviewer 10.1.1.1:3 (example) then I am getting the message “vncviewer : unable to open dislpay ’0.0′ “.
what may be the problem . I checked with echo $DISPLAY >>> it is 0.0.

Reply

33 Mohamed May 5, 2011

This article was helpful. Thanks

Reply

34 Samuel May 13, 2011

Thanks Men, this has worked for me

Reply

35 Roopesh June 9, 2011

Thanks a lot for the solution , It has worked for me .

Reply

36 Kurt November 2, 2011

Thanks very much!! That fixed my ssh problem.

Reply

37 Scott November 9, 2011

Thanks for the solution. Option 1 worked like a charm.

Reply

38 Pratap Kumar December 3, 2011

Amazing, it resolved…

Used this method…
$ ssh-keygen -R server.example.com

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">




Previous post:

Next post: