Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:… – Drew Stephens May 9 '09 at 17:45
up vote 50 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 377d ~/.known_hosts

This deletes line 377 as shown after the colon in the warning:


Alternatively you can remove the relevant key by doing the following

ssh-keygen -R (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
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
Adam's syntax is nearly correct, but you need a space between the "377" and the "d". Also, in OS X, known hosts is located in ~/.ssh/known_hosts ; note the lack of a "." in the filename. – ktappe Oct 22 '15 at 16:10

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
+1 Because this post actually addresses the strict checking portion of the error message. – Shibumi Mar 24 '15 at 21:46
+1 from me as well for addressing the content of the question. Depending on factors there may be more to do. This approach degrades the host checking from "strict" to "some" (my terminology). In my situation that left ssh with permission to keep me from signing in because the way I wanted to sign in was to enter a password, and that was disabled by "some" host checking. So you have to go ahead and direct ssh to use /dev/null as the "UserKnownHostsFile". This sets host checking to "none" in effect and the above DIRE WARNINGS apply, so don't go doing it globally or permanently. – cardiff space man Sep 29 '15 at 1:12

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
All it takes for this error to occur is the target machine being reimaged. If you are connecting to a target that is on your side of a DMZ, a MitM attack is very unlikely. – ktappe Oct 22 '15 at 16:12

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

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
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
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
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
Before you vote down (I am finding people very trigger happy with this), do your research. Read this Security Focus article, 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

As the 'host' [broadly defined, it could be everything from a reinstallation / multiboot to an entirely different computer with an IP address you've connected to before, for instance] appears to the ssh client to have changed, it's giving you the error.

It is unnecessary to switch off strict checking, nor is wholesale deletion of saved keys sensible.

It is quite possible to have two different keys listed in known_hosts for a particular hostname or IP address; giving you 2 alternatives according to whether you think you may need the 'old' key that is currently stored in known_hosts

Either delete the particular key it is referring to, at l377 of known_hosts for the OP, or keep both

The simplest way to keep both, avoiding deletion of keys in known_hosts, is

  1. Edit known_hosts to add # at the start of the 'old' entry referenced in known_hosts [@l377] temporarily
  2. Connect [ssh to the host], agree to the prompt to add the new key 'automatically'
  3. Then re-edit known_hosts to remove the #

more answers at "Add correct host key in known_hosts" / multiple ssh host keys per hostname?

share|improve this answer

protected by Chris S Jun 7 '14 at 2:44

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, 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.