Strovent SystemsSign in
Reference

Read the SSH warning "REMOTE HOST IDENTIFICATION HAS CHANGED"

Line by line, what OpenSSH prints when a host key changes, what the "Offending key" line points to, and how to remove an old key safely.

@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
...
The fingerprint for the ED25519 key sent by the remote host is
SHA256:...
Please contact your system administrator.
Add correct host key in /home/you/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in /home/you/.ssh/known_hosts:12
Host key for example.com has changed and you have requested strict checking.
Host key verification failed.

The host answered with a key that does not match the one your client saved for that name. The client stops before sending any password. Known hosts and fingerprints explains why the check exists. This page explains each line of the message.

The lines

  • "The fingerprint for the ED25519 key sent by the remote host is ..." is the key the host offered now, and the key type. Compare it with a fingerprint you get from the host's owner.
  • "Add correct host key in ... to get rid of this message." is the first known-hosts file, the one that would hold the key you accept.
  • "Offending ED25519 key in /home/you/.ssh/known_hosts:12" is the file and the line number of the saved key that no longer matches. Line 12 is that entry.
  • "Host key for example.com has changed and you have requested strict checking." appears when StrictHostKeyChecking is not no. The client refuses and ends with "Host key verification failed."

Per the ssh_config manual, with the default value ask, and also with yes and accept-new, the client refuses to connect to a host whose key has changed. Only no lets the connection go on, with restrictions, and it is the least safe choice.

"POSSIBLE DNS SPOOFING DETECTED"

If CheckHostIP is on, the client also saves the host's IP address. This second warning says the host key changed and the key saved for the IP address either is unknown, is unchanged or has a different value. It says that either DNS spoofing is happening, or the IP address for the host and its host key have changed at the same time.

What to do

1. Do not accept it blindly. The warning is valid in both harmless and serious cases.

2. Ask the host's owner whether the host was reinstalled, replaced, moved or had its keys regenerated, and ask for the new fingerprint through a route other than this connection. If you run the server, you can avoid this warning on the next key change; see Rotate an SSH host key without warnings: UpdateHostKeys.

3. If the change is expected, remove the old entry and connect again. On a computer, either delete line 12 of the file named in the message, or run:

ssh-keygen -R example.com

-R removes all keys for that host name from the known-hosts file, and works on hashed names. For a port other than 22, give [example.com]:2222. Then connect and check the new fingerprint at the prompt.

4. If the change is not expected, do not connect, and tell the host's owner. Include the host name, the key type and the fingerprint from the message.

In the app, the same event is shown as "HOST KEY CHANGED": see SSH problems.

Sources

Spotted a mistake? Email [email protected].