GrepBoard/Manuals
605 manuals ·

SSH "REMOTE HOST IDENTIFICATION HAS CHANGED": verify, then fix

·Tested on Ubuntu 24.04 (Docker) · OpenSSH 9.6p1 · 2026-10·Test scope ↓·6 steps

SSH "REMOTE HOST IDENTIFICATION HAS CHANGED": the host key differs from known_hosts. Verify the fingerprint out of band, then run ssh-keygen -R.

output
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    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 a host key has just been changed.The fingerprint for the ED25519 key sent by the remote host isSHA256:nC20Hg/3pTd8ZWUH4/qTtNTj6AKYqX/M+En5ujCBQzI.Please contact your system administrator.Add correct host key in /home/bob/.ssh/known_hosts to get rid of this message.Offending ED25519 key in /home/bob/.ssh/known_hosts:1  remove with:  ssh-keygen -f '/home/bob/.ssh/known_hosts' -R '[127.0.0.1]:2222'Host key for [127.0.0.1]:2222 has changed and you have requested strict checking.Host key verification failed.

The host key the server presented does not match the one saved in known_hosts. There are two causes: the server was reinstalled or its keys were replaced (common), or someone is intercepting the connection (rare, and serious). So compare the fingerprint in the message through another channel first, and only then delete the old entry with ssh-keygen -R. Copying the remove with: line and running it right away is the usual mistake.

[1] Note three things from the message.

LineMeaning
The fingerprint for the ED25519 key sent by the remote host is SHA256:…the fingerprint the server sent now; the value to verify
Offending ED25519 key in …/known_hosts:1file and line of the old key
remove with: ssh-keygen -f '…' -R '[127.0.0.1]:2222'the host name to delete ([address]:port when the port is not 22)

[2] Find out whether there is a reason for the change: a reinstall, a different server on the same IP, a recreated instance. Ask the admin or check the change log. If nothing changed and the check in step 3 does not match either, do not connect; report it to whoever handles security.

[3] Get the server's real fingerprint through something other than SSH. Log in through a console (cloud web console, IPMI, hypervisor console) and print the host public key's fingerprint:

console
# ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub256 SHA256:nC20Hg/3pTd8ZWUH4/qTtNTj6AKYqX/M+En5ujCBQzI root@server1 (ED25519)

If it matches the SHA256:… in the warning, the key change is legitimate. Compare like with like: an ED25519 message goes with ssh_host_ed25519_key.pub, ECDSA with ssh_host_ecdsa_key.pub.

[4] If it matches, delete only the old entry, using the host name from the message:

console
$ ssh-keygen -R '[127.0.0.1]:2222'# Host [127.0.0.1]:2222 found: line 1/home/bob/.ssh/known_hosts updated.Original contents retained as /home/bob/.ssh/known_hosts.old

ssh-keygen -R removes only that host's keys and keeps the original as known_hosts.old; rename it back to undo. Ubuntu's default config stores host names hashed, so grep server-name will not find the line. Use ssh-keygen -F '<host>':

console
$ ssh-keygen -F '[127.0.0.1]:2222'# Host [127.0.0.1]:2222 found: line 1 |1|fPJRsLyaySMbgo2hswqL2tFOauM=|yLP0pdo/LghWwJZHo3owQ+w3ZLQ= ssh-ed25519 AAAAC3NzaC1lZDI1...

If you have connected to the same server by both name and IP, remove both (ssh-keygen -R server1.example.com and ssh-keygen -R 192.0.2.10). Remove only one and the warning returns when you use the other.

[5] Connect again to accept the new key. With the default (ask) ssh shows the fingerprint and asks; check it against step 3 once more and type yes. Scripts that cannot prompt (BatchMode=yes) stop at Host key verification failed.

console
$ ssh -p 2222 -o BatchMode=yes -o StrictHostKeyChecking=accept-new alice@127.0.0.1 true && echo LOGIN-OKWarning: Permanently added '[127.0.0.1]:2222' (ED25519) to the list of known hosts.LOGIN-OK

accept-new adds new host keys automatically "but will not permit connections to hosts with changed host keys" (man ssh_config). That is the right value for automation.

[6] Do not bypass it with StrictHostKeyChecking no. The manual says this value lets "connections to hosts with changed hostkeys to proceed, subject to some restrictions." In testing, connecting with -o StrictHostKeyChecking=no to a server whose host key had changed printed the same warning and then logged in with public key authentication. Only password methods were blocked:

output
Password authentication is disabled to avoid man-in-the-middle attacks.Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.UpdateHostkeys is disabled because the host key is not trusted.

The exit code after that output was 0. Had there been an interceptor, the command would have gone to it. Avoid UserKnownHostsFile=/dev/null setups for the same reason.

If you rebuild servers often, do not silence the check; pin host keys through configuration management or distribute new fingerprints to known_hosts. If the public key is rejected after you connect, continue with SSH Permission denied (publickey): find the cause.

Analyze your auth.log (SSH) log in the browser ↗ — nothing is uploaded.

Check it with the ssh_config generator tool ↗ — calculated in your browser.

#ssh#known-hosts#host-key#ssh-keygen