Skip to main contentClaim $5 in free credit — one-time, per account. Claim $5 free
Krova CloudKrova Cloud
Secure Cloud Deployments

SSH Host Key Changed? Verify the Server Before Updating Trust

An SSH host-key warning needs an identity check before a cleanup command. Verify the endpoint and fingerprint, then update only the intended trust entry.

DM
Dhruv Malaviya5 min read
Share
SSH host key verification cover with the Secure Cloud Deployments category, verification headline and subtitle, and a frosted-glass server, key and fingerprint card.

Suppose you rebuild a staging VM, keep its hostname, and try to reconnect. SSH stops with a changed host-key warning. The rebuild makes that warning plausible. It doesn't establish which machine answered.

Before replacing a saved SSH host key, verify the intended server and its new fingerprint through an independent trusted channel. A changed key can follow a legitimate rebuild, a wrong endpoint, or an intercepted connection. The warning alone can't distinguish them.

If the change is unexpected or you can't independently verify the new key, keep the connection blocked and investigate. Don't disable host-key checking, empty your known_hosts file, or accept the key just to clear the warning.

Start with the identity question

Your user key helps the server authenticate you. The server's host key helps your client recognize the server. Generating a new login key won't resolve a mismatch in the identity you're connecting to. OpenSSH describes this trust check in its host verification documentation.

In our hypothetical rebuild, there are two separate facts to establish: the deployment record says the intended VM was replaced, and the key now offered belongs to that replacement. A successful rebuild ticket establishes the first fact. It doesn't establish the second.

  1. Save the warning's hostname or IP address, port, offered key type and full fingerprint, plus the reported known_hosts file and offending entry.
  2. Compare the endpoint with your deployment inventory: intended machine, network mapping, DNS destination and any bastion route. Resolve a wrong endpoint before editing trust.
  3. Obtain the intended server's active public host-key fingerprint through a management channel or administrator whose identity you already trust. The failing SSH connection itself isn't that independent channel.

Inspect what the client remembers

These examples assume a direct OpenSSH connection to the placeholder hostname stage.example, port 2222, using your own ~/.ssh/known_hosts. Substitute the actual values. Follow the warning's file path if it differs; don't edit a system-wide or centrally managed trust file without its owner's process.

ssh-keygen -F '[stage.example]:2222' -f ~/.ssh/known_hosts

The ssh-keygen manual documents this lookup, including hashed hostnames. For the normal port 22, the usual lookup is stage.example rather than the bracketed non-default-port form. This inspects stored trust; it doesn't authenticate the key currently offered.

Aliases deserve extra care. HostKeyAlias changes the identity used for host-key lookup. Custom trust files, host certificates and managed configurations also change the procedure. Establish your actual configuration instead of trying deletion commands against several names until something works.

Get evidence from the intended machine

A trusted administrator can inspect the active host public key on the intended server. For an Ed25519 host key at the standard path, this prints its SHA-256 fingerprint:

ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub -E sha256

The public-key path is documented by sshd; deployments can configure other paths and algorithms. Check the key actually used by that server, and compare the complete fingerprint and algorithm with the client warning. This command reads a public key; you don't need to copy the server's private host key.

A fingerprint is only as useful as its provenance. Reading it from an unverified machine reached over the same suspect route doesn't settle the question. Use an already trusted provisioning record, authenticated management channel, or verified administrator. This article doesn't assume your hosting provider exposes a particular console or fingerprint API.

Matching a trusted fingerprint establishes continuity with that trusted record. It doesn't prove that the operating system, account or application is uncompromised.

Choose the next action from the evidence

What you establishPractical next action
Expected rebuild, correct endpoint, independently verified fingerprint matchesReview a narrowly scoped trust update.
DNS, port mapping or bastion points at another machineCorrect the route; preserve the old trust entry until its status is understood.
No expected change, or fingerprint differs from the trusted recordInvestigate the discrepancy before connecting.
No independent identity evidence availableLeave the connection unresolved and obtain that evidence.

That last outcome is useful. An unresolved identity check is a concrete reason to pause a deployment, not an invitation to choose whichever command makes SSH quiet.

Replace the entry only after verification

Once the identity check passes, preserve a recoverable copy of the affected trust file using your normal backup process. Review the matching entries first. If replacement is appropriate for this exact host and port, the scoped removal is:

ssh-keygen -R '[stage.example]:2222' -f ~/.ssh/known_hosts

-R removes all saved keys for that specified lookup, not just one algorithm. It can therefore remove more than the single line mentioned in the warning. Review that scope before running it; don't erase the entire file or unrelated aliases. Removing a key is maintenance, not identity verification.

Reconnect under your normal host-key policy. If a confirmation prompt appears, compare the fingerprint again with the independently verified record before accepting it. If policy requires keys to be provisioned in advance, use that approved process to install the verified public key. Don't relax the policy to force a prompt.

OpenSSH's StrictHostKeyChecking documentation explains why strict configurations require new keys to be added manually and refuse changed keys. Keep those protections in place.

Don't turn key collection into proof

ssh-keyscan can collect a host's public keys, but collection over the network doesn't independently authenticate that host. Its official manual warns that constructing a trust file from unverified scanned keys leaves users exposed to interception. Piping a fresh scan into known_hosts skips the decision this procedure is meant to make.

After reconnecting, verify the deployment and application separately. If the endpoint or forwarding path is still wrong, use Krova's SSH local port forwarding diagnostic to isolate the failing hop. Connection success and application correctness answer different questions.

Operate a Linux workload on Cube

Krova Cube is the self-managed option for workloads where you need Linux server control. Plan host identity records and your team's SSH trust process alongside deployment and recovery.

Creation context: This article was prepared with AI assistance using the linked primary documentation. The rebuild scenario is hypothetical, the commands are guidance rather than a reported test, and the cover is an AI-generated illustration.

For AI agents:llms.txtsitemap

Related posts