SSH warns that the remote host identification has changed
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!Short answer
ssh compared the server's host key with the one saved in known_hosts and they differ. A rebuilt or reinstalled server, or a reused IP address, is the usual reason, but a man-in-the-middle looks the same. Get the real fingerprint from a trusted channel, compare it, and only then remove the old entry with ssh-keygen -R.
Fix it fast
1Find out which cause you have
Do not delete anything yet. Note the line number in the Offending key message, then fetch the fingerprint the server shows right now and compare it with a value you got another way: the provider console, the server itself, or the person who rebuilt it.
# fingerprint the server presents now ssh-keyscan -t ed25519 server.example.com 2>/dev/null | ssh-keygen -lf - # the entry saved in known_hosts earlier ssh-keygen -F server.example.com2Match what you see, then jump to its fix
- 1
You know the machine was recreated, resized onto new hardware or reinstalled, and the fingerprint from a trusted channel matches what ssh-keyscan returns.The server was rebuilt, reinstalled or restored from an imageFix - 2
The offending line is for an IP address or a short alias, and you recently moved the domain, got a new cloud server that reused an address, or switched networks.The name or address now belongs to a different machineFix - 3
No one changed the server, the trusted fingerprint differs from what the network shows, and the warning appears only from one network (cafe, hotel, office) or after a DNS change you did not make.Nothing was rebuilt and the fingerprint does not match: treat it as an attack until proven otherwiseFix
- 1
What does the error look like?
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!Offending ED25519 key in /home/user/.ssh/known_hosts:12Host key verification failed.
Cause 1 of 3
The server was rebuilt, reinstalled or restored from an image
1Check
A fresh OS install generates new host keys, so the same name or IP now answers with a different key. Do not trust the network to confirm that: read the fingerprint on the machine itself (provider web console, or an already trusted session) and compare it character by character with what the client sees.
# on the server, through the console
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
# on your machine
ssh-keyscan -t ed25519 server.example.com 2>/dev/null | ssh-keygen -lf -2Fix
Only after the two fingerprints match, remove the old entry for that name (and for the IP if it was saved separately), then connect again and check that the fingerprint ssh prints is the one you verified before answering yes.
ssh-keygen -R server.example.com
ssh-keygen -R 203.0.113.10
ssh server.example.com # compare the printed fingerprint, then type yes3Verify
The connection opens with no warning, and known_hosts now holds one entry for the new key.
ssh-keygen -F server.example.comConfirmed by man.openbsd.org
Cause 2 of 3
The name or address now belongs to a different machine
1Check
known_hosts stores a key per name and per address you used. A cloud IP that was released and given to someone else, a DNS record pointed at a new host, or a home router address that now means another device all produce this warning. Look up where the name resolves today and which entries exist.
dig +short server.example.com
ssh-keygen -F 203.0.113.10
ssh-keygen -F server.example.com2Fix
Confirm that the machine now behind the name is the one you meant (provider dashboard, DNS records), verify its fingerprint as above, then remove just the stale entries. Next time, connect by name so one stable entry is used, and use ssh-keygen -R for each stale name or address.
ssh-keygen -R 203.0.113.10
ssh-keygen -R old-alias
ssh server.example.com # compare the printed fingerprint with the verified one before typing yes3Verify
ssh shows a new-host prompt (not the warning) and the fingerprint matches the trusted one.
ssh -v server.example.com 2>&1 | grep -iE 'host key|fingerprint'Confirmed by man.openbsd.org
Cause 3 of 3
Nothing was rebuilt and the fingerprint does not match: treat it as an attack until proven otherwise
1Check
A different key for a host that was not touched means something else is answering: an interception on the path, a hijacked DNS record, or a wrong destination. Compare from another network (for example a phone hotspot) and check DNS from two resolvers.
ssh-keyscan -t ed25519 server.example.com 2>/dev/null | ssh-keygen -lf -
dig +short server.example.com @1.1.1.1
dig +short server.example.com @9.9.9.92Fix
Do not log in, do not type a password, and do not remove the old entry. Leave the default checking on, which refuses a changed key. Report it to the server's owner or provider, review your DNS records and registrar account, and if a login did go through, rotate the credentials and keys used on that host.
# make sure you are on the default (strict for changed keys) behaviour
ssh -G server.example.com | grep -i stricthostkeychecking3Verify
From a trusted network the fingerprint matches the one on the server console again, or the provider confirms the change.
ssh-keyscan -t ed25519 server.example.com 2>/dev/null | ssh-keygen -lf -Confirmed by man.openbsd.org
How do I stop it coming back?
- Write down the host key fingerprints of each server when you create it, in the same place you keep its console login.
- When you rebuild on purpose, restore the old /etc/ssh/ssh_host_* files or announce the new fingerprints to the people who connect.
- Never switch off host key checking to get past the warning; it is the only thing that tells you the server is the one you meant.
- Connect by a stable DNS name instead of a changing IP address.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Security
Entra ID token request fails: the request body must contain the parameter 'grant_type'
AADSTS900144: The request body must contain the following parameter: 'grant_type'.
The token endpoint did not find grant_type in the form body of your POST.
3 causes, each with a fixSecurity
Angular HttpClient does not add the X-XSRF-TOKEN header to a request
403 Forbidden on POST, PUT or DELETE while GET works
Angular copies the XSRF-TOKEN cookie into an X-XSRF-TOKEN header only for mutating requests to the same origin, and only when the cookie is readable by script.
5 causes, each with a fixSecurity
An [Authorize] endpoint rejects a request with a bearer token
Authorization Header sent: no Bearer token sent.
An [Authorize] endpoint without a policy name requires an authenticated user.
4 causes, each with a fixSecurity
ASP.NET Core API rejects an Angular user's token: the signature key was not found
401 Unauthorized
The API looked for the key named by the token's kid in the key set it downloaded from your Authority, and the key was not there.
4 causes, each with a fixSecurity
ASP.NET Core rejects the token before checking it: IDX12741, three segments expected
401 Unauthorized
IDX12741 means the string the API pulled out of the Authorization header is not shaped like a JWT: a signed token has three dot-separated parts and an encrypted one has five.
3 causes, each with a fixSecurity
A Microsoft Entra access token shows Invalid Signature when you check it yourself
Tokens that a Microsoft API receives might not always be a JWT that can be decoded
A token issued for Microsoft Graph is not meant for you to validate, so a failed signature check is expected.
2 causes, each with a fix