Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

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

5 Answers 5

up vote 32 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.

share|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
    
I followed your suggestion but $ sed -i "46 d" ~/.ssh/known_hosts sed: 1: "/Users/myusr/.ssh ...": extra characters at the end of l command so I removed it manually with vim and it worked. Thanx! –  Luis Ramirez-Monterosa Aug 6 '13 at 16:58

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 ?

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

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.

share|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. –  user1797 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. –  user1797 May 8 '09 at 12:14

I think though some of the answers here address the recommended course of action in the OP's question, it does not fully answer the question.

The question states "How to remove strict RSA key checking in SSH and what's the problem here?"

The problem here is, as advised by some others, a change in the host probably due to reinstallation of the server (most common scenario). And the recommended solution is indeed to remove the offending key from the .ssh/authorized_keys file with an inline sed.

However I didnt see any answers address the specific part of the question ""How to remove strict RSA key checking in SSH".

Answer to this anspect of the question: You can remove StrictHostKey checking in your ssh configuration file, typically stored at ~/.ssh/config. An example Host block is provided below:

Host 101
  HostName yourip|hostname
  User youruserid
  IdentityFile /path/to/keyfile
  Port 22
  StrictHostKeyChecking no

The specifically added line is the last one StrictHostKeyChecking no which does just what that. Depending on your specific scenario, this may be useful to you, such as running multiple virtualized containers on a dedicated server, on just a few ips, stopping and starting another instance on the same ip.

share|improve this answer

Another way to remove StrictHostKeyChecking, when you only need to do it for a single server:

ssh <server> -o StrictHostKeyChecking=no
share|improve this answer

protected by Chris S Jun 7 at 2:44

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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