Fix "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" and "Host key verification failed" (SSH)
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Offending ECDSA key in /home/user/.ssh/known_hosts:3 Host key verification failed.
- @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
- Host key for 203.0.113.10 has changed and you have requested strict checking.
- Host key verification failed. fatal: Could not read from remote repository.
- No ED25519 host key is known for github.com and you have requested strict checking.
- Add correct host key in /Users/me/.ssh/known_hosts to get rid of this message.
The host key presented by the server no longer matches the one saved in your ~/.ssh/known_hosts: reinstalled server, reassigned IP address… or an attack. Check the fingerprint through another channel, remove the old entry with ssh-keygen -R host, then reconnect and accept the new key.
What this error means
On the first connection, SSH saves the server’s public key (its "host key") in ~/.ssh/known_hosts. On every later connection, it compares the received key with the saved one: that is what guarantees you are talking to the right server and not to someone intercepting the traffic. If they differ, OpenSSH refuses to continue, prints the warning and points to the offending line (known_hosts:3). "Host key verification failed" alone also shows up when no key is known and the connection is not interactive (CI, script, git clone), because nobody can answer "yes".
Common causes
- Server reinstalled or rebuilt: new OS, new VM or new container, so new host keys were generated.
- IP address or name reassigned: at a cloud provider, an old server’s IP is given to a new one, or a DNS name points to another machine.
- Host key changed by the service: GitHub, for example, replaced its RSA host key on March 24, 2023.
- Non-interactive connection with no known key: CI job, container or script connecting for the first time.
- Man-in-the-middle attack: rare, but it is exactly what this warning is meant to detect, especially on public Wi-Fi.
Step-by-step fix
-
Check why the key changed
Before touching anything, confirm the change is expected: announced reinstall, new IP, change published by the service. Get the real fingerprint through a trusted channel: the provider’s web console, physical access, or official documentation (GitHub publishes its fingerprints).
# on the server itself (web console, KVM, physical access) ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub -
Remove the old key from known_hosts
ssh-keygen -Rremoves every entry for that host and keeps a backup inknown_hosts.old. Use the exact name or IP you connect with, and the bracket notation for a port other than 22. The command is the same on Windows with OpenSSH (file%USERPROFILE%\.ssh\known_hosts).ssh-keygen -R 203.0.113.10 ssh-keygen -R server.example.com ssh-keygen -R "[server.example.com]:2222" -
Reconnect and compare the fingerprint
SSH prints "The authenticity of host … can’t be established" with the
SHA256:…fingerprint. Compare it character by character with the one from step 1, and answeryesonly if they match.ssh [email protected] # for GitHub: ssh -T [email protected] -
CI and scripts: save the key beforehand
In a non-interactive job, add the host key to
known_hostsbefore connecting, then check its fingerprint. The safest is to store the verifiedknown_hostsline in a CI secret rather than scanning it every time.mkdir -p ~/.ssh ssh-keyscan -t ed25519 github.com >> ~/.ssh/known_hosts ssh-keygen -lf ~/.ssh/known_hosts -
Throwaway machines: accept-new rather than no
For test VMs that are recreated often,
StrictHostKeyChecking accept-new(OpenSSH 7.6+) automatically accepts an unknown host but still rejects a key that changed. Do not useStrictHostKeyChecking noorUserKnownHostsFile /dev/null: they fully disable protection against interception, passwords and keys included.# ~/.ssh/config Host *.test.internal StrictHostKeyChecking accept-new
Did this fix work for you?
Confirm it in one click: it will rise for the next developers stuck on the same error.
Keep it from coming back
- When you rebuild a server, keep its host keys (
/etc/ssh/ssh_host_*) or warn users with the new fingerprint. - Connect through a stable DNS name rather than an IP that may be reassigned to another machine.
- Never answer
yesto a new fingerprint without checking it, especially on a public network.
Frequently asked questions
Is it necessarily an attack?
No, it is usually a reinstall or a reassigned IP. But SSH cannot tell the difference: it is up to you to check the fingerprint before accepting the new key.
Can I delete the whole known_hosts file?
It works, but you lose the verified keys of all your servers and will have to check them all again. ssh-keygen -R host only removes the relevant entry.
Why does git clone print "Host key verification failed"?
Git uses SSH for git@… URLs. Either GitHub/GitLab’s key changed (remove it with ssh-keygen -R github.com), or it is not known yet and the session is not interactive: run ssh -T [email protected] once to accept it after checking.
Useful tools for this error
More Systems (Windows, macOS, Linux) errors
- Fix "command not found" and "is not recognized as an internal or external command"
- Fix "running scripts is disabled on this system" in PowerShell
- Fix "xcrun: error: invalid active developer path" on macOS
- Fix "SSL certificate problem: unable to get local issuer certificate" (git, curl, pip, npm)
- Fix "user is not in the sudoers file. This incident will be reported."
- Fix "/bin/bash^M: bad interpreter: No such file or directory"
- Fix "E: Could not get lock /var/lib/dpkg/lock-frontend" (apt, Ubuntu, Debian)
- Fix "App is damaged and can't be opened" on macOS (Gatekeeper)