Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Security

SSH host key changed: verify it, then fix the warning

Why SSH says remote host identification has changed, how to tell a rebuild from interception, verify the new fingerprint, and keep the warning from returning.

CloudSat teamNovember 18, 20267 min read
Abstract illustration of two nearly identical glowing keys side by side, one slightly shifted, floating above a small server outline
On this pageWhat the client is telling you

The loud warning about remote host identification is SSH doing its job. The first time you connect to a server, your client stores the server's public host key. On every later connection it compares, and when the key differs it refuses to continue. Most of the time the cause is harmless: the server was rebuilt, or its address now points at another machine. Occasionally something sits between you and the server. The fix is one command. The work is deciding which case you are in before you run it.

What the client is telling you

A trimmed example from OpenSSH:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:Wq9v1mJcR8a2LkT0bX4hYp7sE3nQ6uDzF5gC1oA8iVs.
Offending ED25519 key in /home/ana/.ssh/known_hosts:12
Host key for 203.0.113.10 has changed and you have requested strict checking.
Host key verification failed.

Three facts are in there: the fingerprint the server just presented, the key type, and the file and line holding the key you trusted before. Each server generates its host key pairs in /etc/ssh/ssh_host_*_key at first boot. Your client keeps the public halves in ~/.ssh/known_hosts, one line per host name or address. A changed key means the machine answering is not the one you met the first time, or it is the same machine with new keys.

Ordinary reasons a key changes

Event Why the key differs
The server was rebuilt or reinstalled A fresh system generates new host keys on its first boot
A new server received an address you used before Different machine, same IP
A floating IP moved to a replacement server The address now reaches another machine
A snapshot from before a key change was restored The old keys came back with the old disk
An admin rotated the host keys Intended, ideally announced
One DNS name points at several servers Each server has its own keys

If none of these happened, treat the warning as a possible interception until you prove otherwise. That matters most on networks you do not control, such as hotel or conference Wi-Fi.

Decide before you delete anything

  1. Ask what changed. Check your change log, your team chat and your provider's history of the server. On CloudSat, the activity log records rebuilds, snapshot restores and floating IP assignments with their times.
  2. Check the network you are on. If you are on a network you do not trust, stop and try again from one you do.
  3. Compare fingerprints. Get the real fingerprint through a channel an attacker on the network path cannot touch, then compare it with the one in the warning.

Get the fingerprint the server should have

The most reliable channel is the provider's web console, which reaches the server without SSH. On CloudSat, request console access (VNC) from the server's Access tab, sign in, and print every host key fingerprint:

for k in /etc/ssh/ssh_host_*_key.pub; do ssh-keygen -lf "$k"; done

Each line shows the key size, the SHA256 fingerprint, a comment and the type, such as (ED25519). Compare the line whose type matches the warning. Other trustworthy sources: a colleague whose verified session is still open, the configuration management that deployed the keys, or SSHFP records in a DNSSEC-signed zone.

Do not use ssh-keyscan as proof. It fetches the key over the same network you are worried about, so an interceptor would hand it the same fake key.

Remove the old entry and reconnect

Once the change is explained and the fingerprint matches, remove the stale entries. Remove every name you use for the server, because the client stores the name and the address separately:

ssh-keygen -R 203.0.113.10
ssh-keygen -R web-01.example.com
ssh-keygen -R '[203.0.113.10]:2222'    # entry for a server on a non-standard port
ssh-keygen -F 203.0.113.10             # confirm nothing is left

ssh-keygen -R also finds hashed entries and keeps the previous file as known_hosts.old. Then connect again. The client shows the new fingerprint and asks whether to continue. Instead of typing yes, you can paste the fingerprint you obtained from the console: OpenSSH compares the two and continues only if they match.

On Windows, the built-in OpenSSH client uses the same commands in PowerShell and keeps its file in $env:USERPROFILE\.ssh\known_hosts. PuTTY stores host keys in the registry under HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys and shows its own security alert with the new fingerprint, where you accept the new key once you have checked it. WinSCP keeps a separate cache, so it may warn again after PuTTY is fixed.

Two shortcuts to avoid: deleting the whole known_hosts file, and connecting with -o StrictHostKeyChecking=no. Both silence the warning by switching off the check for every server you know, not just this one.

Keep the warning from coming back

Planned changes do not have to produce a scare every time. Pick the approach that matches how your servers change:

  • Carry the keys across rebuilds. Back up /etc/ssh/ssh_host_* before a planned rebuild and restore them afterward, then restart SSH. Treat those files like any private key: whoever holds them can impersonate the server.
  • Share keys inside a failover pair. When a floating IP moves between two servers that play the same role, install the same host keys on both so clients see one identity.
  • Let clients learn new keys. With UpdateHostKeys, which current OpenSSH turns on by default unless you changed UserKnownHostsFile, a server can announce additional keys to clients that already trust it. Add the new key on the server, let clients connect for a while, then retire the old one.
  • Publish SSHFP records. ssh-keygen -r web-01.example.com prints DNS records for the server's keys. With VerifyHostKeyDNS yes, clients trust keys that match a secure fingerprint from DNS. This is only as strong as DNSSEC on the zone and validation on the resolver.
  • Use host certificates. For a fleet, sign each server's host key with a certificate authority and teach clients to trust the authority once. Rebuilt servers get a new certificate, and nobody sees a warning.
# On a machine that keeps the CA key offline
ssh-keygen -t ed25519 -f host_ca -C "example.com host CA"
ssh-keygen -s host_ca -I web-01 -h -n web-01.example.com,203.0.113.10 -V +52w ssh_host_ed25519_key.pub

Copy the resulting ssh_host_ed25519_key-cert.pub to /etc/ssh/ on the server, add HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub to sshd_config, check it with sudo sshd -t and reload SSH. On each client, one line in known_hosts covers every signed server in the domain:

@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK3q8vX2... example.com host CA

For automation, StrictHostKeyChecking=accept-new is the honest middle ground: it records keys for hosts it has never seen, but still refuses keys that changed. Better still, have provisioning write the known key into the file before the first connection.

FAQ

Is it safe to just run ssh-keygen -R?

Only after you know why the key changed. The command itself is harmless, but the next connection trusts whatever key answers. If you skip the check, you may trust an interceptor's key from that moment on.

Why does one name warn and another does not?

The client checks the name or address you typed against its own entry. If you connect by IP and by host name, each has a line, and only the one you used is compared. Remove both when the server is replaced.

Two of my servers show the same host key. Is that a problem?

Yes. They were cloned from one image or snapshot without new keys, so each can impersonate the other. On each clone, run sudo rm /etc/ssh/ssh_host_*, then sudo ssh-keygen -A to generate a fresh set, and restart SSH while your current session stays open.

Can I verify the key the very first time I connect?

Yes, and you should. The first connection shows a fingerprint and asks the same question. Compare it with the console output above before you accept it, because that first answer decides what your client trusts from then on.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.