I have a Linux server that whenever I connect it shows me the message that changed the SSH host key:

$ ssh root@host1 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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 93:a2:1b:1c:5f:3e:68:47:bf:79:56:52:f0:ec:03:6b. Please contact your system administrator. Add correct host key in /home/emerson/.ssh/known_hosts to get rid of this message. Offending key in /home/emerson/.ssh/known_hosts:377

RSA host key for host1 has changed and you have requested strict checking. Host key verification failed.

It keeps me for a very few seconds logged in and then it closes the connection.

host1:~/.ssh # Read from remote host host1: Connection reset by peer Connection to host1 closed.

Does anyone know what's happening and what I could do to solve this problem?

link|improve this question
This dupes earlier question: serverfault.com/questions/2988/… – Drew Stephens May 9 '09 at 17:45
feedback

3 Answers

up vote 15 down vote accepted

Please don't delete the entire known_hosts file as recommended by some people, this totally voids the point of the warning. It's a security feature to warn you that a man in the middle attack may have happened.

I suggest you identify why it thinks something has changed, most likely an SSH upgrade altered the encryption keys due to a possible security hole. You can then purge that specific line from your known_hosts file:

sed -i "377 d" ~/.known_hosts

This says remove line 377 as shown after the colon in the warning:

/home/emerson/.ssh/known_hosts:377

Alternatively you can remove the relevant key by doing the following

ssh-keygen -R 127.0.0.1 (Obviously replace with the servers IP)

Please DO NOT purge the entire file and ensure this is actually the machine you want to be connecting to prior to purging the specific key.

link|improve this answer
Not going to delete over 350 servers because of one key mismatch. Any idea why it keeps closing the connection? – setatakahashi May 9 '09 at 0:25
Is it not solved once you remove the relevant known_hosts record? If not, could you run the ssh client in verbose mode and pastebin it somewhere. – Adam Gibbins May 9 '09 at 8:47
1  
It's closing the machine because the host key is invalid, just like it says. If you are serious about security, you need to check with the server's admin to make sure the host key changed for a legitimate reason. If so, you can replace it, as explained by Adam. – Matthew Flaschen May 9 '09 at 19:07
feedback

First of all, is this your machine ? Did you knowingly change the host keys ? If not I would be very concerned that something has altered that data.

Secondly, turn up the ssh debuging,

ssh -vvv user@host

and see what that tells you, also try looking in, /var/log/secure and /var/log/messages on the server you are trying to connect to for clues, sshd gives good error messages.

Thirdly, is this machine connected to the internet ? Should you really be allowing root logins ?

link|improve this answer
+1 for the root logins comment – fahadsadah Jun 20 '10 at 16:17
feedback

You are getting this because something has changed (like new NIC, new IP, change on server software, etc). Security focus has a nice article on SSH host key protection.

Just remove the key (using SFTP or similar) from the server, by editing the $HOME/.ssh/known_hosts file, and accept the new one upon next connection.

Your connection might be getting dropped because of the StrictHostKeyChecking setting. See this thread for a similar issue.

link|improve this answer
2  
Noooo, please don't do this. This totally voids all security this feature provides. Please only remove the specific key that has changed, not all known_hosts. – Adam Gibbins May 8 '09 at 11:52
3  
I did not recommend to remove the known_hosts file, I recommended to edit it, and remove the key from it. – David Collantes May 8 '09 at 11:55
Ooop, sorry, misread. – Adam Gibbins May 8 '09 at 11:56
2  
This message can certainly not be triggered by a new IP address, much less by a new NIC. See Adam Gibbins' correct answer. – bortzmeyer May 8 '09 at 12:05
1  
Before you vote down (I am finding people very trigger happy with this), do your research. Read this Security Focus article, securityfocus.com/infocus/1806. I quote a bit of it: "Why can a host key change? The machine to which you wish to connect has been moved to a different DNS name or IP address, or it's been replaced by a new one entirely." If an answer is horribly incorrect, please allow the chance for a correction. After all, this is a wiki. – David Collantes May 8 '09 at 12:14
show 2 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.