WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

If you use ssh for a while, you are sure to get this message sooner or later: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!. This means more or less what it says – the machine formerly known as somemachine suddenly smells different. The possible reasons are:

  • It’s a new machine using the name, or the IP address (you would know)
  • You regenerated the ssh keys (you would know).
  • You are not talking to the machine you think you are (e.g. a dynamic IP address that points somewhere else).
  • There’s a man in the middle. This is bad (very bad, in fact).

If you are using key based authentication, you’ll still get in if it is your machine. The hypothetical or real man in the middle gets to pass your traffic or block it, but cannot read the text. To check that there is no man in the middle, you should examine the host key with

ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key

That key should match what your ssh client reported as the server identity:

$ ssh -p24 root@somemachine
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
4d:16:9d:69:a0:f5:a9:ae:bc:96:f5:0b:ba:e0:ae:94.
Please contact your system administrator.
Add correct host key in /home/stuff/.ssh/known_hosts to get rid of this message.
Offending key in /home/stuff/.ssh/known_hosts:38
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Port forwarding is disabled to avoid man-in-the-middle attacks.
Last login: Wed Jun  7 08:01:30 2011 from 192.168.0.55
[root@localhost ~]# ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key
2048 4d:16:9d:69:a0:f5:a9:ae:bc:96:f5:0b:ba:e0:ae:94 /etc/ssh/ssh_host_rsa_key.pub

They match. That machine was reinstalled, so it’s a new operating system and a new identity. It was fine. Finding out how to make the warning/error go away is left as an exercise to the reader.

This entry was posted in Stuff and tagged , , . Bookmark the permalink.