How to fix "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!"

Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with OpenSSH 9.6p1, client and server, November 29, 2026.

SSH saved the server’s key the first time you connected, and the server is now presenting a different one. If you know why (the server was rebuilt, reinstalled or replaced), remove the old entry and connect again:

ssh-keygen -R example.com
ssh example.com

For a server on a non-standard port, the entry is stored with brackets: ssh-keygen -R '[example.com]:2222'. SSH prints the exact command in the warning, so you can copy it from there.

We reproduced this with OpenSSH 9.6 by generating a new host key on a test server after connecting once. The next connection printed the full warning and refused to continue; after ssh-keygen -R, the connection asked to add the new key and then worked.

What the warning means

@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
The fingerprint for the ED25519 key sent by the remote host is
SHA256:6HjC7noCf6BecUrYu4Ed1pnN94tB9JHf6unl+UVosXE.
Offending ED25519 key in /home/you/.ssh/known_hosts:1
  remove with:
  ssh-keygen -f '/home/you/.ssh/known_hosts' -R '[127.0.0.1]:2222'
Host key verification failed.

The warning is loud because a changed key is exactly what a man-in-the-middle attack looks like. Almost always the cause is harmless:

Likely cause Example
Server rebuilt or OS reinstalled You recreated a VM or droplet
Raspberry Pi or home device reflashed A fresh SD card makes new host keys for the same raspberrypi.local name or IP
IP or hostname reused A new cloud instance got an old instance’s IP
Load balancer or DNS now points elsewhere git.example.com moved to a new host
SSH server reinstalled with new keys Host keys regenerated
A real interception Unexpected, on an untrusted network

Fix: check, then remove the old key

  1. Check the new fingerprint if you can. On the server (or its web console): ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub. It should match the SHA256: value in the warning.
  2. Remove the stale entry: ssh-keygen -R hostname (use the exact host and port form from the warning).
  3. Connect again and answer yes when SSH asks to add the new key.

ssh-keygen -R keeps a backup of your file as known_hosts.old, so the change is easy to undo.

Remove it by line number instead

The warning names the line: Offending ED25519 key in /home/you/.ssh/known_hosts:1 means line 1. You can delete that line yourself, which helps when the host is listed under an alias or old IP:

sed -i '1d' ~/.ssh/known_hosts          # Linux
sed -i '' '1d' ~/.ssh/known_hosts       # macOS

On Windows the file is C:\Users\you\.ssh\known_hosts; open it in a text editor and delete the numbered line, or run ssh-keygen -R hostname in PowerShell. We tested the Linux commands only.

For GitHub, GitLab and other services

If the warning appears for github.com, compare the fingerprint with the one the service publishes before removing anything. GitHub lists its current keys in its SSH key fingerprints documentation. Services do rotate keys: GitHub replaced its RSA host key on 24 March 2023, and anyone with the old key saved saw this warning. For GitHub that blog post gives the one-line fix, ssh-keygen -R github.com, followed by adding the published key.

Confirm it worked

The connection goes through, and ssh-keygen -F hostname shows one entry for the host. If the warning comes back for a server nobody changed, stop and find out why before you connect.

FAQ

Is it safe to remove the old host key?

Yes, once you know why the key changed. If you rebuilt the server, reinstalled its OS or the IP now points at a new machine, removing the old key is the right fix. If you don't know of any change, check the new fingerprint with whoever runs the server first.

How do I check a server's fingerprint?

On the server, run ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub. Compare the SHA256: value with the one in the warning. Cloud consoles often show it in the instance's boot log.

Should I set StrictHostKeyChecking no?

No. It hides this warning for every server, including the one time it's a real attack. Remove the single stale entry instead. For automation, StrictHostKeyChecking accept-new adds new hosts but still refuses changed keys.

What does Host key verification failed mean on its own?

SSH has no saved key for the host and can't ask you (for example in CI or with BatchMode), or the saved key changed. Add the host first with ssh-keyscan host >> ~/.ssh/known_hosts after checking its fingerprint.