← Back to section · Digital Security

Host Keys and Trust Establishment: The TOFU Model, known_hosts, and Certificate-Based Host Identity

SSH security rests on a question that is often skipped: how do you know you are connecting to the target machine itself? This article dissects the structural weakness of trust on first use (TOFU), how known_hosts works and is governed, and how host certificates and SSHFP move the trust anchor from per-machine checking to centralised issuance.

Published 22 November 2026 · 6 min read · PQ Frontier

Host Keys and Trust Establishment: The TOFU Model, known_hosts, and Certificate-Based Host Identity
AI-generated site artwork
Video explainer · SSH Security: Keys and Access Control

The Skipped Step: What Are You Actually Connecting To?

SSH’s encryption and authentication are designed quite solidly, but the whole chain rests on a plain premise: the client must first confirm that the peer really is the target host. That confirmation relies on the host key — the server presents its host public key during the handshake, and the client compares it against local records. The problem is that on the first connection there are no local records at all.

OpenSSH’s default behaviour is to show the fingerprint and ask whether to continue. Almost everyone types yes. That is trust on first use (TOFU): the key seen the first time is accepted unconditionally and written into known_hosts, and from then on the only check is “is it the same as last time.” TOFU defends against a persistent man-in-the-middle — an attacker appearing a second time with a different key triggers the warning — but it cannot defend against the first connection being hijacked, because there is no “correct value” to compare against.

This is not an implementation flaw but a design trade-off: SSH introduced no global PKI and left trust establishment to the user. In the era of individuals administering a machine or two, that was good enough; in organisations with hundreds or thousands of machines and frequent staff changes, it becomes the weakest link in the whole system.

known_hosts: A Consistency Ledger, Not a Source of Truth

The known_hosts file is essentially a local ledger: each line records “this hostname/IP corresponds to this public key.” Connection logic has exactly three outcomes: match, and proceed; mismatch, and warn loudly and refuse; no record, and run the TOFU flow. The reason the famous “man-in-the-middle warning” in that message is so often ignored is that its common triggers are in fact benign: machine reinstalls, cloud instance rebuilds, host-key rotation, load balancers landing you on a different node.

So the real-world failure mode is not an attacker breaking something — it is operators being trained to type yes at warnings. For warnings to regain meaning, the organisation must answer one question: where is the authoritative list of correct host keys? The possible answers form a governance maturity ladder:

  • Collect every host key across the fleet into one authoritative GlobalKnownHostsFile and distribute it to every client via configuration management;
  • In cloud environments, deliver host-key fingerprints at instance initialisation through an out-of-band channel (such as the cloud provider’s console log or metadata), eliminating “trust the network path on first connection”;
  • Use HashKnownHosts to hash the local ledger, so a leaked ledger does not directly expose internal topology — a privacy measure only; it does not change the trust semantics.

Certificate-Based Host Identity: Moving the Trust Anchor to a CA

OpenSSH’s certificate system covers the host side too. An administrator uses a CA private key to sign a server’s host public key into a host certificate, stating the list of hostnames it may represent (principals) and its validity period; the server presents the certificate via HostCertificate, and the client needs only one line in known_hosts — @cert-authority *.example.com <CA public key> — to trust every host identity that CA issues.

This changes the shape of trust: new machines coming online no longer create new TOFU events — CA issuance completes the identity registration; host-key rotation needs only re-issuance, with zero client changes; the hostname list is inside the certificate, so impersonating another hostname is cryptographically impossible. The cost is that the CA itself becomes a high-value target and issuance needs approval and audit — but that is exactly what a governance problem should look like: risk concentrated from countless “type yes” moments into a single point that can be specifically defended.

SSHFP: Fingerprints in DNS

The other route is the SSHFP record defined by RFC 4255: publish the host key’s fingerprint in DNS, and have the client query and compare it at connection time. Its security depends entirely on the authenticity of DNS, so it must be paired with DNSSEC — SSHFP without signature validation merely moves trust from the network path to the DNS path, and VerifyHostKeyDNS only auto-accepts records carrying valid DNSSEC signatures.

SSHFP applies more narrowly than host certificates (it depends on DNS infrastructure maturity), but in organisations that have already deployed DNSSEC it provides centralised distribution without running a CA. The two routes are not mutually exclusive; both express the same principle: host identity must have a governable distribution channel, and TOFU should be a fallback, not the institution.

Back to the original question: whether an SSH connection is secure depends half on the algorithms used after you log in, and half on what grounds you had for trusting the peer before you logged in. Upgrading the second half from personal habit to organisational institution is the real hardening of SSH’s trust system.

After the Warning: Turning Response into a Procedure

The host-key change warning is one of the few signals in SSH security that actively jumps out and stops the user — but its value depends on whether the response actions are defined in advance. In environments without a procedure, the response relies on individual improvisation and usually ends with deleting the old record and accepting the new key — the warning mechanism dismantled by hand. In environments with a procedure, a warning triggers a fixed sequence:

First, stop. Do not delete the old record from known_hosts, and do not assert “it must have been a reinstall.” The old record is the only evidence; delete it and even retrospective comparison becomes impossible. Second, verify out of band. Obtain the new key’s fingerprint through a channel unrelated to SSH — the cloud console’s instance log, the configuration management system’s registry, the out-of-band management network in the machine room — and compare it character by character with the fingerprint in the warning. The essence is “out of band”: asking “are you really you” over the very network path that may be hijacked is the same as not asking. Third, leave a record. Note the reason for the change (reinstall, rotation, rebuild) in the asset register, so that when the same machine warns again, the responder can see the previous conclusion and its basis.

Cloud environments amplify this: autoscaling and immutable infrastructure turn host-key changes from rare events into daily ones, and manual out-of-band verification for each is unrealistic. The way out is to automate host-key registration in the instance lifecycle — at initialisation, write the fingerprint into a trusted registry that clients consult before connecting rather than connecting first and asking later, or use host certificates to eliminate per-machine registration altogether. The end state of the response procedure is making “key change warnings” rare again: every expected change triggers no warning, and the warnings that remain are exactly the anomalies a human should look at.

References

Tags: SSHHost KeysTrust Modelsknown_hosts