Skip to content
  1. LuzineDebug
  2. Systems (Windows, macOS, Linux)
  3. WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
Systems (Windows, macOS, Linux) Beginner ≈ 5 min to fix

Fix "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" and "Host key verification failed" (SSH)

Error message
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.
In short

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.

Be the first to confirm this fix

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

  1. Server reinstalled or rebuilt: new OS, new VM or new container, so new host keys were generated.
  2. 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.
  3. Host key changed by the service: GitHub, for example, replaced its RSA host key on March 24, 2023.
  4. Non-interactive connection with no known key: CI job, container or script connecting for the first time.
  5. 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

  1. 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).

    bash
    # on the server itself (web console, KVM, physical access)
    ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
  2. Remove the old key from known_hosts

    ssh-keygen -R removes every entry for that host and keeps a backup in known_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).

    bash
    ssh-keygen -R 203.0.113.10
    ssh-keygen -R server.example.com
    ssh-keygen -R "[server.example.com]:2222"
  3. 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 answer yes only if they match.

    bash
    ssh [email protected]
    # for GitHub:
    ssh -T [email protected]
  4. CI and scripts: save the key beforehand

    In a non-interactive job, add the host key to known_hosts before connecting, then check its fingerprint. The safest is to store the verified known_hosts line in a CI secret rather than scanning it every time.

    bash
    mkdir -p ~/.ssh
    ssh-keyscan -t ed25519 github.com >> ~/.ssh/known_hosts
    ssh-keygen -lf ~/.ssh/known_hosts
  5. 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 use StrictHostKeyChecking no or UserKnownHostsFile /dev/null: they fully disable protection against interception, passwords and keys included.

    plaintext
    # ~/.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 yes to 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

All Systems (Windows, macOS, Linux) errors →