SSD Nodes Learn Hosting plans →
Guides Matt ConnorBy Matt Connor

Verify SSH host keys with SSHFP records

Publish SSHFP records so ssh can verify a server's host key on first connect, then test whether DNSSEC and your resolver's AD bit make ssh trust them.

How SSHFP records verify an SSH host key

SSHFP records let you verify an SSH host key on the first connection, by publishing the key's fingerprint in DNS. When you connect, ssh looks up the record and compares it with the key the server sends. That comparison only proves something when DNSSEC (Domain Name System Security Extensions) signs the record and your resolver tells ssh that it checked the signature.

That last part is where most setups fail without any error. This guide publishes the records and then tests whether your client really treats them as secure. On a default Ubuntu host, that test matters more than any other step.

The first-connection problem

The first time you connect to a server, ssh has no record of its host key. It prints a fingerprint and asks if you want to continue. Most people type yes without checking. That habit is called trust on first use: whatever key answers the first time becomes the trusted key. An attacker who sits between you and the server on that first connection becomes the server you trust. If how SSH works is new to you, the host key is the server's identity. It is separate from the user key that logs you in, which managing your SSH keys covers.

To check the key properly you need a second channel that the attacker does not control. You have four common options:

  • Read the fingerprint from your provider's web console. Log in through the console, run ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub, and compare the SHA256: string with the one ssh shows you.
  • Pre-load known_hosts from configuration management, which works well when you manage several Linux servers from one machine.
  • Sign host keys with an SSH certificate authority, so clients trust one CA key instead of every host key. The trade-offs are covered in centralizing Linux logins with LDAP or an SSH CA.
  • Publish SSHFP records in a DNSSEC-signed zone, which is the rest of this guide.

SSHFP suits a small fleet where you already control the DNS zone. It needs no extra software on the client, only one setting.

What an SSHFP record contains

An SSHFP record holds an algorithm number, a fingerprint type number, and the fingerprint as hex. The format comes from RFC 4255, and later RFCs added the newer key types. The numbers come from the IANA registry:

  • Algorithm 1 is RSA.
  • Algorithm 2 is DSA.
  • Algorithm 3 is ECDSA.
  • Algorithm 4 is Ed25519.
  • Algorithm 6 is Ed448.
  • Fingerprint type 1 is SHA-1.
  • Fingerprint type 2 is SHA-256.

A modern Ed25519 host key with a SHA-256 fingerprint is therefore a record that starts 4 2. RFC 7479 gives this example:

ssh.example.com IN SSHFP 4 2 a87f1b687ac0e57d2a081a2f282672334d90ed316d2b818ca9580ea384d92401

The SHA-256 value is the same hash that ssh-keygen -lf prints as SHA256:.... DNS stores it as hex and ssh displays it as base64, so the two strings look different even when they describe the same key.

Generate SSHFP records with ssh-keygen -r

Run this on the server, not on your laptop, because you need the server's own host keys. First list them:

ls /etc/ssh/ssh_host_*_key.pub

A typical Ubuntu server has ECDSA, Ed25519 and RSA host keys. Print a SHA-256 record for each one, using the name clients will type to connect:

for k in /etc/ssh/ssh_host_*_key.pub; do
  ssh-keygen -r host.example.com -f "$k" -O hashalg=sha256
done

The output is one line per key:

host.example.com IN SSHFP 3 2 <64 hex characters>
host.example.com IN SSHFP 4 2 <64 hex characters>
host.example.com IN SSHFP 1 2 <64 hex characters>

-r prints the SSHFP resource record for the public key file you give with -f. Without -O hashalg=sha256 it prints two lines per key, one SHA-1 and one SHA-256, because the default is to print both. The OpenBSD man page describes this hashalg option under the -D flag, but the text is about printing SSHFP records, which is what -r does. If your DNS software does not accept the SSHFP type by name, add -g, which prints the records in generic DNS format.

Check your OpenSSH version with ssh -V, and read man ssh-keygen on your own system before you rely on an option, because older releases may differ.

Why publish only SHA-256 records

RFC 6594 says that when both SHA-1 and SHA-256 records exist for a server, a client must prefer the SHA-256 one. It also says the client must reject a key that fails the SHA-256 check, instead of trying the SHA-1 record. A SHA-1 record therefore adds nothing for a modern client.

OpenSSH has also said, in the release notes for 10.1 (6 October 2025) and 10.2 (10 October 2025), that a future release will deprecate SHA-1 SSHFP records because of weaknesses in SHA-1. When that happens, ssh will ignore SHA-1 records and ssh-keygen -r will print only SHA-256 ones. This is an announcement, not a shipped change. SHA-256 SSHFP support has existed since OpenSSH 6.1 in 2012, so publishing only SHA-256 records costs you nothing on any client you are likely to meet.

Publish a record for every host key

Publish one record per host key, not only the Ed25519 one. The reason is in how ssh compares records. ssh compares each record with the single key the server presented, and it skips records for a different algorithm. If records exist for the name but none of them is for the presented key's algorithm, the result is "found" without "match". In the OpenSSH source, that path prints the changed-key warning.

There is a second rule in the same code. If a record has the same algorithm and fingerprint type as the presented key but a different fingerprint, ssh marks the check as failed, and a failure cancels any match. So you cannot publish an old and a new Ed25519 record side by side during a key change. The rotation section below works around this.

Add the records at your DNS host

An SSHFP record is only useful in a zone signed with DNSSEC. On Cloudflare, turn on DNSSEC from the DNS Settings page with Enable DNSSEC. Cloudflare then shows the values for a DS (delegation signer) record. Add that DS record at your registrar. DNSSEC is not active until the parent zone publishes the DS record. If your registrar does not list algorithm 13, it may call it "ECDSA Curve P-256 with SHA-256". Cloudflare adds the DS record for you only for domains on Cloudflare Registrar and for .ch and .cz domains. Every other domain needs the manual step.

Cloudflare supports SSHFP as a record type. Its API stores a record as three data fields: algorithm, type and fingerprint. Map them from the ssh-keygen line: the first number is algorithm, the second is type, and the hex string is fingerprint. With an API token that can edit DNS for the zone:

curl -s https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records \
  -H "Authorization: Bearer $CF_API_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"type":"SSHFP","name":"host.example.com","data":{"algorithm":4,"type":2,"fingerprint":"<64 hex characters>"}}'

Repeat it for each line ssh-keygen printed. If you use the dashboard instead, the form asks for the same values, whatever labels it gives them.

If you run your own DNS server with a zone file, paste the lines as ssh-keygen printed them, then fix the name. In a zone file, host.example.com without a trailing dot is read as relative to the zone. Write host.example.com. with the dot, or use the short name host. Then re-sign the zone the way your DNS software requires.

Check that the records are signed

dig is in the bind9-dnsutils package if your system does not have it. Ask for the records with DNSSEC data:

dig +dnssec SSHFP host.example.com

The answer section should list your SSHFP records and an RRSIG record next to them. The RRSIG shows the zone is signed. It does not show that anyone checked the signature. The flags: line near the top tells you that: an ad flag (authenticated data) means the resolver you asked validated the answer. Canonical's server documentation says the same thing: ad in a response means DNSSEC validation ran and succeeded.

Do not be surprised if the ad flag is missing when you query your local resolver. That is the subject of the section after next.

Why a matching SSHFP record proves nothing without DNSSEC

SSHFP defends against an attacker on the network path who answers your SSH connection with their own key. An attacker in that position can usually also answer your DNS query. If the DNS answer is not signed, they send an SSHFP record that matches their own key, and the match is worthless.

RFC 4255 says this directly: a key verified with SSHFP "MUST NOT be trusted" if the record was not authenticated by DNSSEC. A client that does not validate signatures itself must use a secure channel to the system that does. The RFC also notes that DNSSEC only protects the fingerprint after the zone administrator signs it. If the fingerprint reaches your DNS zone through an insecure path, the signature protects the wrong value.

OpenSSH follows this rule by asking one question: did the resolver set the AD bit? OpenSSH does not validate DNSSEC itself. In its source, a record set counts as validated only when the answer came back with AD set. A validated match is "secure". Any other match is "insecure", and ssh will not trust it on its own.

Does Ubuntu's systemd-resolved pass the AD flag to ssh?

This is an open question for this guide, so treat what follows as a prediction to test, not a result. On Ubuntu, /etc/resolv.conf normally points at the systemd-resolved stub resolver on 127.0.0.53. For ssh to see an AD bit, every link in this chain has to hold. Here it is, read from current source code and documentation, not from a running system:

  1. OpenSSH's built-in lookup code asks for DNSSEC data only when edns0 is set in the resolver options. It never turns edns0 on by itself. A build linked against the ldns library uses a different lookup path, which this guide did not check.
  2. glibc 2.31 and later remove the AD bit from every answer unless trust-ad is set in /etc/resolv.conf. The option is opt-in because it means you trust both the resolver and the network path to it.
  3. The stub file that current systemd writes contains options edns0 trust-ad, so links 1 and 2 hold on a host that uses it.
  4. In current systemd source, the stub sets AD in a reply only for answers it validated itself. It does not copy an AD bit from the upstream server.
  5. Ubuntu ships systemd-resolved with DNSSEC validation off. The Ubuntu 26.04 resolved.conf man page says DNSSEC= defaults to "no". Upstream systemd defaults to allow-downgrade, but that default does not apply on Ubuntu.

Put together, the source suggests that a default Ubuntu client will report your signed records as insecure, and that setting DNSSEC= to allow-downgrade or yes should change that. We have not run this on a live Ubuntu 24.04 or 26.04 host. Run the test below and trust what you see over the theory.

First, check what your resolver configuration says:

ls -l /etc/resolv.conf
grep -E '^(nameserver|options)' /etc/resolv.conf

You want to see nameserver 127.0.0.53 and options edns0 trust-ad. If you replaced /etc/resolv.conf with your own file and it has no trust-ad, glibc strips the AD bit before ssh sees it, whatever the resolver did.

Next, ask the stub directly and look for ad on the flags: line:

dig +dnssec SSHFP host.example.com @127.0.0.53

Then test ssh itself. UserKnownHostsFile=/dev/null makes every connection a first connection, and StrictHostKeyChecking=yes stops ssh from prompting, so the result is a clean pass or fail:

ssh -v -o VerifyHostKeyDNS=yes -o UserKnownHostsFile=/dev/null \
  -o StrictHostKeyChecking=yes host.example.com exit

Look for one of these debug lines from OpenSSH:

debug1: found 3 secure fingerprints in DNS
debug1: found 3 insecure fingerprints in DNS

With secure and a matching key, ssh trusts the key from DNS and the command connects. With insecure, ssh does not trust the key on DNS alone, so strict checking refuses it and the command ends with Host key verification failed.

Now turn on validation in systemd-resolved with a drop-in file, as Ubuntu's DNSSEC documentation describes:

sudo mkdir -p /etc/systemd/resolved.conf.d
printf '[Resolve]\nDNSSEC=allow-downgrade\n' | sudo tee /etc/systemd/resolved.conf.d/dnssec.conf
sudo systemctl restart systemd-resolved

Run the dig and ssh commands again. Then change the file to DNSSEC=yes, restart, and run them a third time. Write down ssh -V and systemctl --version next to each result, because the behavior belongs to those versions.

Know what each mode costs before you keep it. DNSSEC=yes validates every lookup, and a lookup that fails validation fails completely, so a broken zone anywhere becomes a name you cannot reach. That is the kind of failure described in DNSSEC lookups failing after a root key rollover. DNSSEC=allow-downgrade turns validation off when the upstream server does not seem to support DNSSEC, and the systemd man page warns that this makes it open to downgrade attacks. For SSHFP the downgrade fails safe: a downgraded answer carries no AD bit, so ssh sees "insecure" and falls back to asking you. It does not produce a false "secure".

Turn on VerifyHostKeyDNS on the client

VerifyHostKeyDNS is off by default. Turn it on for the hosts you published records for, in ~/.ssh/config on your laptop:

Host *.example.com
    VerifyHostKeyDNS yes

With yes, ssh trusts a key that matches a secure fingerprint from DNS, with no prompt. An insecure match is handled as if you had set ask: ssh shows the normal new-key prompt with one extra line, Matching host key fingerprint found in DNS. That line is a hint, not proof. Compare the fingerprint another way before you answer.

Two side effects are worth knowing. First, ssh skips the DNS lookup when you connect by IP address, and -v prints skipped DNS lookup for numerical hostname. Connect by the name you published. Second, the man page says UpdateHostKeys is on by default only when VerifyHostKeyDNS is not enabled, so turning this option on also turns off automatic host key updates in known_hosts.

Check your client version before you enable the option. CVE-2025-26465 was a logic error in ssh from 6.8p1 to 9.9p1 that let an on-path attacker impersonate any server when VerifyHostKeyDNS was enabled. OpenSSH 9.9p2, released 18 February 2025, fixed it. Distributions often backport the fix without changing the upstream version number, so on Ubuntu check the package changelog:

ssh -V
apt changelog openssh-client | grep CVE-2025-26465

A line naming the CVE means your package has the fix. While you are on the server side, the rest of hardening SSH on a VPS and the advice on the SSHole flaw in OpenSSH are worth a look too.

What happens when the host key changes and the record goes stale

Host keys change when you reinstall a server or move to a new VPS. The SSHFP records do not change with them. Clients with VerifyHostKeyDNS enabled then find records that do not match the key they receive.

In the current OpenSSH source, ssh handles that by printing the full changed-key warning, starting with WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!, followed by this line:

Update the SSHFP RR in DNS with the new host key to get rid of this message.

After that, ssh continues with its normal known_hosts check, so what happens next depends on StrictHostKeyChecking and what is already in known_hosts. The default ask setting refuses a host whose known key has changed. To see the exact output on your own versions, rotate a host key on a test server and leave the old record in place.

A stale record and a new record for the same algorithm cannot sit side by side (see the section on publishing a record for every host key). So change keys in this order:

  1. A day before, lower the TTL (time to live) on the SSHFP records to a few minutes, so caches drop the old values quickly.
  2. Replace the host key on the server.
  3. Run the ssh-keygen -r loop again and replace the old records with the new ones.
  4. Flush the resolver cache on any client that looked up the old records. On Ubuntu that is resolvectl flush-caches, and flushing the DNS cache on Ubuntu covers the other resolvers.
  5. Remove the old key from each client's known_hosts with ssh-keygen -R host.example.com.
  6. Run the ssh -v test from the AD-flag section and check for secure.

Add the SSHFP step to the checklist you use for a new server, next to the steps in the first ten minutes on a new VPS, so a rebuild does not leave stale records behind.

FAQ

Do SSHFP records work without DNSSEC?

They are looked up, but they prove nothing. An attacker who can answer your SSH connection can usually forge an unsigned DNS answer too. RFC 4255 says a key verified this way must not be trusted unless DNSSEC authenticated the record. OpenSSH marks a match as "insecure" when the answer had no AD bit, and then asks you to confirm the key instead of trusting it.

Why does ssh -v say "found 3 insecure fingerprints in DNS" when my zone is signed?

A signed zone is not enough. ssh needs the AD bit from the resolver, and glibc removes it unless /etc/resolv.conf has trust-ad. On Ubuntu, the systemd-resolved stub ships with DNSSEC=no, and its source suggests it sets AD only for answers it validated itself. Check grep options /etc/resolv.conf, then try DNSSEC=allow-downgrade or DNSSEC=yes in a drop-in under /etc/systemd/resolved.conf.d/ and run the test again.

Should I publish SHA-1 SSHFP records as well as SHA-256?

No. RFC 6594 says clients must prefer SHA-256 when both exist and must not fall back to SHA-1 when the SHA-256 check fails. OpenSSH has announced that a future release will ignore SHA-1 SSHFP records. Generate records with ssh-keygen -r host.example.com -f /etc/ssh/ssh_host_ed25519_key.pub -O hashalg=sha256, and repeat it for each host key.

Does SSHFP work when I connect to a server by IP address?

No. OpenSSH skips the DNS lookup for a numeric host, and ssh -v prints skipped DNS lookup for numerical hostname. Connect with the DNS name you published the records under, and turn on VerifyHostKeyDNS yes for that name in ~/.ssh/config.

Was this article useful?