VPS Tutorials
SSH host identification changed: verify the fingerprint before reconnecting
When SSH warns that a VPS host key changed, verify the instance, IP and fingerprint through the provider console before removing stale known_hosts entries and reconnecting.

SSH suddenly displays WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! and ends with Host key verification failed. The server is presenting a host key different from the one your client previously saved. Reinstalling a VPS, changing its IP or restoring a snapshot can explain this, but incorrect DNS or an intercepted connection can produce the same warning. Verify the server's identity before updating the local record; do not disable host-key checking.
| Confirmed situation | Appropriate action |
|---|---|
| You rebuilt the VPS and can independently confirm its new fingerprint through the provider console | Back up known_hosts, remove only that host's old entries, then reconnect and compare the fingerprint |
| A domain or IP changed and may point to a different machine | Compare DNS, the console's instance IP and SSH configuration before changing records |
| There was no expected change, or the console and connection fingerprints differ | Stop connecting, retain the warning and old entries, and investigate DNS, jump hosts and provider changes |
A host key is not your SSH login private key. It identifies the server to the client. Deleting a local known_hosts entry neither changes your login key nor proves the new server is trustworthy. OpenSSH issues the warning to prevent server impersonation and man-in-the-middle attacks; see the ssh manual.
If you normally connect using an alias such as ssh dev-vps, run this on your local computer:
ssh -G dev-vps | grep -Ei '^(hostname|port|user|userknownhostsfile|hostkeyalias|proxyjump) '
Inspect hostname, port, hostkeyalias and proxyjump. HostName can be a domain or IP. A custom port, jump host or separate UserKnownHostsFile affects which record to inspect. Compare the result with the instance IP in your provider console. For a domain, check current DNS against the intended instance; an unchanged domain name does not prove it still reaches the same machine.
Use ssh-keygen -F to find saved records, including hashed known_hosts entries:
ssh-keygen -F example.com
ssh-keygen -F 203.0.113.10
Replace the example domain and IP with your own. For a nondefault port such as 2222, searching and removal use the [主机]:端口 form:
ssh-keygen -F '[example.com]:2222'
The warning's Offending ... key in ...known_hosts:17 points to a possible conflicting entry. Manually deleting line 17 can remove the wrong record and does not address duplicates or hashed entries. Prefer OpenSSH's -F and -R; the ssh-keygen manual documents host and custom-port syntax.
Open your provider's web, VNC or serial console and confirm it is the intended instance. This access does not depend on the SSH connection currently giving the warning. Run on the server console:
ssh-keygen -l -E sha256 -f /etc/ssh/ssh_host_ed25519_key.pub
The output's SHA256:... is the fingerprint of the current ED25519 host public key. Compare it character for character with the ED25519 fingerprint in the warning or connection prompt. If the client shows ECDSA or RSA, compare the same key type using /etc/ssh/ssh_host_ecdsa_key.pub or /etc/ssh/ssh_host_rsa_key.pub. Fingerprints from different algorithms are not interchangeable. The sshd manual lists server host-key file locations.
A provider-supplied fingerprint is also useful if it corresponds to the current instance and current key type. If you cannot obtain an independent value, a fingerprint collected by scanning the network is not independent proof.
For example, this command only retrieves the public key offered at the destination port; it does not authenticate the server:
ssh-keyscan -T 5 -p 22 -t ed25519 example.com 2>/dev/null | ssh-keygen -l -E sha256 -f -
Compare the scanned result with the console or another trusted source before relying on it. The ssh-keyscan manual warns that adding unverified scanned keys to a trust file exposes you to man-in-the-middle attacks.
Run the following on your local computer, starting with a backup:
cp -p ~/.ssh/known_hosts ~/.ssh/known_hosts.backup.$(date +%Y%m%d%H%M%S)
If the file is missing, your account may not use the default known_hosts. Check userknownhostsfile in the output of ssh -G and the file named in the warning. Creating an empty default file will not fix a conflict in another file.
For a domain on the default port 22:
ssh-keygen -R example.com
If you also used the IP directly, remove its old entry separately only after confirming it is the same intended instance:
ssh-keygen -R 203.0.113.10
For port 2222:
ssh-keygen -R '[example.com]:2222'
If ssh -G or the warning points to a custom file, specify that file with -f:
ssh-keygen -R example.com -f ~/.ssh/project_known_hosts
ssh-keygen -R removes matching host records, including hashed entries. It is more targeted than deleting all of ~/.ssh/known_hosts. You must first have independently verified the new fingerprint and established why the host changed.
For the default port, reconnect:
ssh -o StrictHostKeyChecking=ask [email protected]
Compare the new prompt with the console fingerprint of the same key type. Enter yes only if they match exactly. After login, inspect the new record with ssh-keygen -F example.com. With an alias, custom port or jump host, use your usual verified connection command; do not bypass the warning by switching to an unverified address.
StrictHostKeyChecking=accept-new automatically accepts keys for new hosts, not changed keys. StrictHostKeyChecking=no relaxes handling of changed keys and is not an appropriate repair here. Consult the ssh_config manual for the option semantics.
A new OS normally generates new host keys while the client retains the old public key. Remembering a reinstall explains a possible change but does not replace fingerprint verification. Confirm the instance and new fingerprint in the console before removing entries.
Compare DNS with the console IP, then inspect HostName, ProxyJump and HostKeyAlias in SSH configuration. A domain pointing to a new VPS naturally presents a different host key, but that new machine still needs independent verification.
These tools generally invoke an SSH client. Reproduce it in the local terminal, verify the fingerprint and remove the specific stale entries, then retry the tool. See the VS Code Remote SSH guide for connection settings. If identity verification succeeds but the error becomes Permission denied (publickey), continue with SSH key login configuration.
Do not enter yes or disable checking. Preserve the warning and inspect the console instance, IP, DNS, jump host and SSH settings. Ask the provider about migration or key rotation if necessary. Continue only when the destination and fingerprint are both accounted for.
- Record the warning's host, port, key type and fingerprint.
- Confirm the destination using
ssh -G, the provider console and DNS. - Obtain the current instance's fingerprint for the same key type through the console.
- Once the fingerprint and reason for change are confirmed, back up
known_hostsand remove that host withssh-keygen -R. - Compare the fingerprint again when reconnecting, then log in.
Keep the order: verify identity, remove stale records, reconnect. It resolves expected host-key changes after a VPS rebuild while preserving SSH's server-identity protection.