I've been using ssh to log-in to a remote server I rent for several years. Last week I got a message from them saying they upgraded my account and server. Now when I go to login, I get this message from ssh

The RSA host key for mydomain.com has changed,
and the key for the corresponding IP address X.X.X.X
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
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/myaccount/.ssh/known_hosts to get rid of this message.
Offending key in /home/myaccount/.ssh/known_hosts:7
RSA host key for mydomain.com has changed and you have requested strict checking.
Host key verification failed.

Now, I assume that this has been triggered by my host upgrading my server. So I want to trust this site again. But I can't quite see how.

I looked in known_hosts and all there are there are public-keys. But I can't tell which of these comes from the old version of this particular server. Nor do I know how to get a correct key for the host; the previous time I made contact, I think ssh just confirmed with me and automatically saved it. Now it says I've requested strict checking, but I have no idea when I did this or where to reset it.


The line:

Offending key in /home/myaccount/.ssh/known_hosts:7

indicates that the old key is on line 7 of your known_hosts file. Use your favourite editor to delete line 7. That should make it go away.

You can also use ssh-keygen -R to remove a entry:

# ssh-keygen -R hostname -f ~/.ssh/known_hosts

FYI, those are not public keys but a hashed representation of the hosts.

You can list the known hosts file with:

$ ssh-keygen -lv -f ~/.ssh/known_hosts

It will then display the key and ascii art representation:

2048 0f:3b:8a:02:75:f1:68:0f:32:8a:7a:0f:ef:69:f8:a0 |1|aa3F96t0nzhqLpt+lJx4msNAGQI=|740B4+NTrQhAx/DWXHf6QLrBpz8= (RSA)
+--[ RSA 2048]----+
|                 |
|  .              |
|   =             |
|o * .            |
|o= o    S        |
|+   .    +       |
|..o.    o .      |
|..++.o . .       |
|E. *B .          |

In theory you print this out and keep it in a safe place. When something suspicious happens you have a copy for reference.

  • See note from Matt below about double checking with the hosting provider. – davey Jan 19 '10 at 21:37

I'm going to just add that before taking the advice of my esteemed fellow serverfaulties and erasing the line from your known_hosts file, you should talk to customer service at the other end and make sure that they did do something that would have caused this key change.

  • 2
    yes, good point :-) – interstar Jan 21 '10 at 21:50

You'll need to edit your /home/myaccount/.ssh/known_hosts file and remove the entry that matches the IP address or hostname of your old server. Afterwards, you should just ssh to your server like you normally do and it will prompt you with a new key and ask if you want to add it. Simply say 'yes' and that's that! :) It shouldn't ask you again unless something has changed.

Hope that helps.

EDIT: your known_hosts entry would most likely look something like this

[hostname or IP address] [keytype, generally ssh-rsa] [key here, i.e. ASDFJAKj3klje35u9086095468kjflADf...]

  • If HashKnownHosts is enabled then the ip address/hostname will not be readable in your known_hosts. If that is the case the line number reported by the ssh client is about the only thing you have to work with. – Zoredache Jan 19 '10 at 20:30
  • 1
    thanks, Glen and Zoredache. It's exactly Zoredach's problem I had. – interstar Jan 21 '10 at 21:49
  • Hugely upvoted answers didn't work for me but this did. – Nick Manning Sep 10 '15 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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