What the message looks like
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Host key verification failed.Common causes
- The server was reinstalled or its SSH keys were regenerated.
- The IP address or hostname now belongs to a different machine, for example after a cloud rebuild.
- A load balancer or a cluster hands out different servers with different keys.
- DNS points to a different host than before.
- Rarely: someone is intercepting the connection.
Check
- Which key is stored for this host?
ssh-keygen -F server.example.com - Fingerprint the server shows now
ssh-keyscan -t ed25519 server.example.com 2>/dev/null | ssh-keygen -lf - - Fingerprint on the server itself (use the console or a trusted channel)
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
Fix
- Compare the two fingerprints. If they match the new server you expect, continue.
- Remove only the old entry:
ssh-keygen -R server.example.com(and the IP address if it is listed too). - Connect again and accept the new key after checking its fingerprint.
- If the key changed and you did not expect it, do not connect. Ask the owner or use the provider's console.
- For rebuilt servers that should keep their identity, restore the old
/etc/ssh/ssh_host_*files from backup.
Typical scenario
You reinstalled a VPS from your hosting provider's panel; the IP address stayed the same. On the next ssh the big warning appears, including the line "Offending ECDSA key in /home/you/.ssh/known_hosts:12". The operating system generated new host keys during the rebuild. Compare the fingerprint with the one the provider's console or a colleague with access gives you before you delete the old entry.
FAQ
Can I turn the warning off with StrictHostKeyChecking=no?
Technically yes, but it removes the protection against interception. Fix the entry instead, and never use that option permanently.
Why does it appear after every rebuild of my cloud server?
A new server generates new host keys. Automate the cleanup with ssh-keygen -R in your rebuild script, or keep and restore the host keys.
What does the line number in "Offending key in known_hosts:12" mean?
It is the line in your ~/.ssh/known_hosts that holds the old key. You can remove exactly that line. More convenient is ssh-keygen -R servername, which finds the matching entry itself and keeps a backup as known_hosts.old.
Does ssh-keygen -R delete other servers too?
No, it only removes entries for the given name or address, and it also works with a hashed known_hosts. If the server is also listed under its IP address, run the command for that as well, otherwise ssh keeps warning.
How do I verify the new fingerprint without trusting the connection blindly?
Print it on the server through the provider console with ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub and compare it with what ssh shows when connecting. SSHFP records in DNS also help if you maintain them and use VerifyHostKeyDNS.