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

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

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
XXxXXXXXXX
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.

share|improve this question

3 Answers 3

up vote 8 down vote accepted

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.

share|improve this answer
    
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.

share|improve this answer
1  
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...]

share|improve this answer
    
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
    
thanks, Glen and Zoredache. It's exactly Zoredach's problem I had. –  interstar Jan 21 '10 at 21:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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