20.3. SSH Certificates and Hardware-Backed Authentication

Keys do not scale. A hundred servers times a dozen administrators is over a thousand authorized_keys lines to install, audit, and remove - and every host-key rotation means touching every client's known_hosts. SSH certificates invert the problem: a certificate authority (CA) key signs short-lived certificates, servers and clients trust the CA, and granting or withdrawing access becomes a signing decision instead of a file distribution campaign. This section builds both halves - a user CA that servers trust for login, and a host CA that clients trust for server identity - then covers expiry, revocation, and the hardware-backed keys that take the private key off disk entirely.

SSH certificate trust directions

Figure 20.2. The two trust directions. Left: the user CA signs john's public key, and sshserver trusts the CA through TrustedUserCAKeys. Right: the host CA signs sshserver's host key, and john's client trusts that CA through an @cert-authority record. Each CA private key is the single thing worth protecting.

20.3.1. User and Host Certificate Authorities and Trust Distribution

Create a user CA - an ordinary key pair whose only job is signing other keys. With ~/.ssh as the working directory:

$ ssh-keygen -t ed25519 -C "user CA" -f ca_user
Generating public/private ed25519 key pair.
Your identification has been saved in ca_user
Your public key has been saved in ca_user.pub
The key fingerprint is:
SHA256:AfuPzX2q6ZxcUxcysjToHhbxxyzoRHFaWs9XuiP3y/0 user CA
The key's randomart image is:
+--[ED25519 256]--+
|      .  +.+    .|
|       o. @ =  ..|
|      . .B * O.o |
|       .+.o * +..|
|        S= .. = .|
|        o=.. + + |
|        ..+ + + .|
|         o + +. o|
|         .B..  oE|
+----[SHA256]-----+

The modes deserve the same check as any key material:

$ stat -c "%a %U:%G %n" ~/.ssh/ca_user ~/.ssh/ca_user.pub
600 john:john /home/john/.ssh/ca_user
644 john:john /home/john/.ssh/ca_user.pub

A CA key is different from a login key in one way: whoever holds it can mint credentials for every account that trusts it. Give it a passphrase, using a copy so the exercise can keep the unprotected original:

$ cp ~/.ssh/ca_user ~/.ssh/ca_user_protected

The copy is silent. Add the passphrase - ssh-keygen first asks for the current one (none on this copy: press Enter), then the new one twice:

$ ssh-keygen -p -f ~/.ssh/ca_user_protected
Key has comment 'user CA'
Your identification has been saved with the new passphrase.

Reading it without the passphrase now fails, exactly as with the login key in Section 20.2.1:

$ ssh-keygen -y -f ~/.ssh/ca_user_protected < /dev/null
Enter passphrase for "/home/john/.ssh/ca_user_protected": Load key "/home/john/.ssh/ca_user_protected": incorrect passphrase supplied to decrypt private key

Remove the practice copy (rm prints nothing). The pattern to keep: a real CA key stored offline and passphrase-protected, with only its public half distributed.

$ rm ~/.ssh/ca_user_protected

Now the host CA, the same way:

$ ssh-keygen -t ed25519 -C "host CA" -f ca_host
Generating public/private ed25519 key pair.
Your identification has been saved in ca_host
Your public key has been saved in ca_host.pub
The key fingerprint is:
SHA256:RoamyzTMdfz2aNYu0RvsLUt8RsFgA/m8+7y/pGPwrv4 host CA
The key's randomart image is:
+--[ED25519 256]--+
|          .o+    |
|       o  .. +   |
|      + =  o  o  |
|   o + + .  o  . |
|    *   S oo ..  |
|   o o . ..*=.   |
|    o     +oB=o. |
|         o.o=B+  |
|          .+BE=+o|
+----[SHA256]-----+

Record both CA fingerprints - they are what servers and clients will compare when trust is distributed:

$ ssh-keygen -lf ~/.ssh/ca_user.pub
256 SHA256:AfuPzX2q6ZxcUxcysjToHhbxxyzoRHFaWs9XuiP3y/0 user CA (ED25519)
$ ssh-keygen -lf ~/.ssh/ca_host.pub
256 SHA256:RoamyzTMdfz2aNYu0RvsLUt8RsFgA/m8+7y/pGPwrv4 host CA (ED25519)

Server-side trust for the user CA. Copy ca_user.pub to sshserver (any trusted channel; Section 20.5.3 shows the SSH-path way) and install it where sshd can read it, on sshserver as john:

$ sudo install -m 644 ~/debian-handbook/ssh/ca_user.pub /etc/ssh/ch20_user_ca.pub

The command prints nothing on success; check the result:

$ ls -l /etc/ssh/ch20_user_ca.pub
-rw-r--r-- 1 root root 89 Nov 21 23:07 /etc/ssh/ch20_user_ca.pub

Point the practice instance at it. The port 2222 instance now switches from authorized_keys to certificates - replace /etc/ssh/sshd_config.ch20 with the certificate variant:

# /etc/ssh/sshd_config.ch20 (on sshserver) - certificate variant
Port 2222
AddressFamily inet
ListenAddress 0.0.0.0
HostKey /etc/ssh/ssh_host_ed25519_key
PidFile /run/sshd-ch20.pid
LogLevel VERBOSE
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
UsePAM no
AuthenticationMethods publickey
AllowUsers john
AuthorizedKeysFile none
TrustedUserCAKeys /etc/ssh/ch20_user_ca.pub
Subsystem sftp internal-sftp

AuthorizedKeysFile none removes plain keys from the table: from here on, this instance accepts only certificates signed by the user CA, with AllowUsers john still gating the account. Restart the instance with the new configuration, on sshserver in the root shell:

# kill "$(cat /run/sshd-ch20.pid)"
# /usr/sbin/sshd -f /etc/ssh/sshd_config.ch20

Both are silent. Confirm the listener came back:

# ss -ltnp | grep :2222
LISTEN 0      128          0.0.0.0:2222      0.0.0.0:*    users:(("sshd",pid=16220,fd=6))

Client-side trust for the host CA. The host side needs a server key to sign. Generate a dedicated host key for the exercise, on sshserver in the root shell:

# ssh-keygen -q -t ed25519 -N "" -C "sshserver host key" -f /etc/ssh/ssh_host_ed25519_key_ch20cert

With -q it prints nothing. Bring the public half back to the workstation's workspace as hostcert.pub (any trusted channel), then sign it with the host CA, with the workspace as the working directory:

$ ssh-keygen -s ~/.ssh/ca_host -h -I sshserver-host -n 192.168.221.20 -V -5m:+30m hostcert.pub
Signed host key hostcert-cert.pub: id "sshserver-host" serial 0 for 192.168.221.20 valid from 2026-11-21T23:02:56 to 2026-11-21T23:37:56

-h makes this a host certificate, -n 192.168.221.20 is the principal - the name the certificate is valid for. Inspect the result:

$ ssh-keygen -L -f hostcert-cert.pub | grep -E "Type:|Principals:|Valid:"
        Type: ssh-ed25519-cert-v01@openssh.com host certificate
        Valid: from 2026-11-21T23:02:56 to 2026-11-21T23:37:56
        Principals:

Copy hostcert-cert.pub to sshserver and install it beside the host key, on sshserver as john:

$ sudo install -m 600 ~/debian-handbook/ssh/ssh_host_ed25519_key_ch20cert-cert.pub /etc/ssh/ssh_host_ed25519_key_ch20cert-cert.pub

Silent on success. A second practice instance presents key plus certificate on port 2224:

# /etc/ssh/sshd_config.ch20host (on sshserver)
Port 2224
AddressFamily inet
ListenAddress 0.0.0.0
HostKey /etc/ssh/ssh_host_ed25519_key_ch20cert
HostCertificate /etc/ssh/ssh_host_ed25519_key_ch20cert-cert.pub
PidFile /run/sshd-ch20host.pid
LogLevel VERBOSE
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
UsePAM no
AllowUsers john
AuthorizedKeysFile none
TrustedUserCAKeys /etc/ssh/ch20_user_ca.pub
Subsystem sftp internal-sftp

Start it, on sshserver in the root shell (validate first, exactly as before - both steps are silent, then check the listener):

# /usr/sbin/sshd -t -f /etc/ssh/sshd_config.ch20host
# /usr/sbin/sshd -f /etc/ssh/sshd_config.ch20host
# ss -ltnp | grep :2224
LISTEN 0      128          0.0.0.0:2224      0.0.0.0:*    users:(("sshd",pid=16388,fd=6))

The client side of host trust is a known_hosts record with a marker. Place the host CA's public key in the workspace with an @cert-authority prefix for each name pattern it should cover:

# ~/debian-handbook/ssh/known_hosts.cert (on sshadmin)
192.168.220.30 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFDj61pe37pck4oCCdxzhvQpI5SRdHMxXUmRF9OKRZMl root@trixie
@cert-authority 192.168.221.20 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG/5u/EL5qwhdZUC0hlpdY+XXq54eKWyctwhAQz0RTrJ host CA
@cert-authority [192.168.221.20]:2224 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG/5u/EL5qwhdZUC0hlpdY+XXq54eKWyctwhAQz0RTrJ host CA

The first line is the jump host's ordinary record - the jump still uses a plain host key. The marked lines say: for these destinations, accept any host certificate signed by this CA whose principal matches. Connect through the jump with that trust file:

$ ssh -p 2224 -o UserKnownHostsFile=~/debian-handbook/ssh/known_hosts.cert sshserver hostname
sshserver

The certificate was checked against the CA record, not against a per-host key record. Contrast that with a plain record file - the same server, but the client was told to expect a bare key:

$ ssh -p 2224 -o UserKnownHostsFile=~/debian-handbook/ssh/known_hosts.plain sshserver hostname
Host key verification failed.

The plain record does not match what the server now presents, and the connection is refused rather than downgraded. Trusting a host CA is a separate, explicit act; it does not silently absorb existing records. The payoff is operational: a new server joined the fleet needs a signed host certificate and a CA record that may already cover it, and a host key rotation means signing the new key once - not editing known_hosts on every client.

20.3.2. Signing Short-Lived Certificates with Principals and Restrictions

A user certificate is the user CA's signature over a public key plus policy: who the key may act as, how long, and with which restrictions. Sign john's key with a 30-minute window, with ~/.ssh as the working directory:

$ ssh-keygen -s ca_user -I john@sshadmin -n john -V -5m:+30m id_ed25519.pub
Signed user key id_ed25519-cert.pub: id "john@sshadmin" serial 0 for john valid from 2026-11-21T23:01:55 to 2026-11-21T23:36:55

The signing options:

ssh-keygen signing option Description
-s ca_key The CA key that signs.
-I key_id Human-readable identity stamped into the certificate - what logs and audits display.
-n principals The account name(s) the certificate may log in as; the server requires the target account to match one.
-V validity Time window: relative (-5m:+30m - from five minutes ago for thirty minutes) or absolute (20200101:20200102).
-z serial Serial number distinguishing certificates from the same CA. The default is zero on every signing, so issue deliberate serials when one certificate must be revoked without affecting the others (Section 20.3.3).
-O option Certificate restriction: force-command="...", source-address=..., no-pty, or clear to drop all default extensions.
-h Make it a host certificate instead of a user certificate.

The result lands next to the private key as id_ed25519-cert.pub - the client automatically offers key and certificate together. Inspect it:

$ ssh-keygen -L -f ~/.ssh/id_ed25519-cert.pub
/home/john/.ssh/id_ed25519-cert.pub:
        Type: ssh-ed25519-cert-v01@openssh.com user certificate
        Public key: ED25519-CERT SHA256:qyMz9bqiKx9uB05niCGdzTH6kGsN8K/Kge030pr7zig
        Signing CA: ED25519 SHA256:AfuPzX2q6ZxcUxcysjToHhbxxyzoRHFaWs9XuiP3y/0 (using ssh-ed25519)
        Key ID: "john@sshadmin"
        Serial: 0
        Valid: from 2026-11-21T23:01:55 to 2026-11-21T23:36:55
        Principals:
                john
        Critical Options: (none)
        Extensions:
                permit-X11-forwarding
                permit-agent-forwarding
                permit-port-forwarding
                permit-pty
                permit-user-rc

Every field is policy the server enforces. Use it against the certificate-only instance on port 2222:

$ ssh -p 2222 sshserver hostname
sshserver

No authorized_keys entry was consulted - sshd accepted the key because the user CA vouched for it, the principal john matched the target account, and the clock was inside the validity window. Remove the certificate and the same login fails, because the bare key is no longer authorized on that instance:

$ mv ~/.ssh/id_ed25519-cert.pub ~/.ssh/id_ed25519-cert.pub.off

The move is silent, and the login now refuses:

$ ssh -p 2222 sshserver hostname
john@192.168.221.20: Permission denied (publickey).

Restore it (again silent) and the login works again:

$ mv ~/.ssh/id_ed25519-cert.pub.off ~/.ssh/id_ed25519-cert.pub

The principal is what binds a certificate to an account, and a mismatch is a refusal. Park the working certificate (the copy prints nothing) and sign one whose principal is alice, still with ~/.ssh as the working directory:

$ cp id_ed25519-cert.pub id_ed25519-john-cert.pub
$ ssh-keygen -s ca_user -I alice -n alice id_ed25519.pub
Signed user key id_ed25519-cert.pub: id "alice" serial 0 for alice valid from 2026-11-21T23:02:27 to 2026-11-21T23:37:27

Connecting as john with it fails:

$ ssh -p 2222 sshserver hostname
john@192.168.221.20: Permission denied (publickey).

sshd checked the certificate's principals against the account being logged into and found no match. Restore john's certificate (both moves are silent):

$ mv ~/.ssh/id_ed25519-cert.pub ~/.ssh/alice-cert.pub
$ mv ~/.ssh/id_ed25519-john-cert.pub ~/.ssh/id_ed25519-cert.pub

Restrictions travel inside the certificate. Sign one that forces a single command regardless of what the client asks to run:

$ cp id_ed25519-cert.pub id_ed25519-normal-cert.pub
$ ssh-keygen -s ca_user -I forced -n john -O force-command="/usr/bin/id" id_ed25519.pub
Signed user key id_ed25519-cert.pub: id "forced" serial 0 for john valid from 2026-11-21T23:02:32 to 2026-11-21T23:37:32
$ ssh -p 2222 sshserver hostname
uid=1001(john) gid=1001(john) groups=1001(john),27(sudo)

The client asked to run hostname; the server ran /usr/bin/id instead, because the certificate said to. force-command in a certificate is the same mechanism as command= in an authorized_keys line (Section 20.4.3) - useful for keys handed to automation jobs that should only ever run one thing. source-address= restricts where the holder may connect from, and -O clear strips the default extensions (pty, forwarding, X11) down to whatever the signer re-adds. Restore the unrestricted certificate (silent moves):

$ mv ~/.ssh/id_ed25519-cert.pub ~/.ssh/forced-cert.pub
$ mv ~/.ssh/id_ed25519-normal-cert.pub ~/.ssh/id_ed25519-cert.pub

20.3.3. Certificate Expiry, Revocation, and CA Key Protection

Validity windows make most revocation unnecessary: an expired certificate is dead the moment its window passes, with nothing to distribute. Park the working certificate and mint a deliberately expired one:

$ cp id_ed25519-cert.pub id_ed25519-valid-cert.pub
$ ssh-keygen -s ca_user -I expired -n john -V 20200101:20200102 id_ed25519.pub
Signed user key id_ed25519-cert.pub: id "expired" serial 0 for john valid from 2020-01-01T00:00:00 to 2020-01-02T00:00:00

Confirm what the certificate claims:

$ ssh-keygen -L -f ~/.ssh/id_ed25519-cert.pub | grep Valid
        Valid: from 2020-01-01T00:00:00 to 2020-01-02T00:00:00

Then try it. At normal verbosity the client shows only the refusal; -vvv shows the certificate being offered and turned down. Selected output - the full run prints hundreds of protocol-negotiation lines around these:

$ ssh -vvv -p 2222 sshserver hostname
debug1: identity file /home/john/.ssh/id_ed25519 type 3
debug1: identity file /home/john/.ssh/id_ed25519-cert type 7
debug1: Offering public key: /home/john/.ssh/id_ed25519 ED25519-CERT SHA256:qyMz9bqiKx9uB05niCGdzTH6kGsN8K/Kge030pr7zig explicit
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
john@192.168.221.20: Permission denied (publickey).

The certificate was offered (ED25519-CERT, type 7), the server refused it, and the client had nothing else to try. The server knows why and records it: at the instance's LogLevel VERBOSE, sshd logs the expiry reason, while the client only ever sees Permission denied - a diagnostic asymmetry that recurs throughout SSH. Restore the valid certificate (silent moves):

$ mv ~/.ssh/id_ed25519-cert.pub ~/.ssh/expired-cert.pub
$ mv ~/.ssh/id_ed25519-valid-cert.pub ~/.ssh/id_ed25519-cert.pub

Expiry handles time; revocation handles mistakes. A certificate KRL scoped to the CA revokes a certificate by its serial:

$ ssh-keygen -k -s ~/.ssh/ca_user -f ~/debian-handbook/ssh/revoked-certs.krl ~/.ssh/id_ed25519-cert.pub
Revoking from /home/john/.ssh/id_ed25519-cert.pub

-s records which CA the revocation applies to, and the certificate being revoked identifies its own serial - no CA private key is used here, only its public half. Install the file on sshserver (replacing the Section 20.2.4 KRL at the same path, /etc/ssh/ch20_revoked_keys), make the instance point at it, validate, and reload - on sshserver in the root shell, appending one line:

# printf "RevokedKeys /etc/ssh/ch20_revoked_keys\n" >> /etc/ssh/sshd_config.ch20
# /usr/sbin/sshd -t -f /etc/ssh/sshd_config.ch20
# kill -HUP "$(cat /run/sshd-ch20.pid)"

All three are silent. The SIGHUP reload re-reads the configuration without dropping the listener, and existing sessions continue under the rules they started with - Section 20.4.4 shows that property being used deliberately. From sshadmin, the now-revoked certificate is refused:

$ ssh -p 2222 sshserver hostname
john@192.168.221.20: Permission denied (publickey).

Mint a fresh certificate with a new serial - still with ~/.ssh as the working directory:

$ ssh-keygen -s ca_user -z 1 -I john@sshadmin-serial -n john -V -5m:+30m id_ed25519.pub
Signed user key id_ed25519-cert.pub: id "john@sshadmin-serial" serial 1 for john valid from 2026-11-21T23:02:47 to 2026-11-21T23:37:47
$ ssh -p 2222 sshserver hostname
sshserver

The KRL revoked serial 0 certificates from this CA; serial 1 is a different certificate and works. That is the operational distinction between the two revocation tools of this chapter: revoke a serial when a certificate was mis-issued or an emergency cutoff is needed, and revoke the underlying key - as the Section 20.2.4 KRL did - when the private key itself is compromised, because then every certificate on it is suspect.

Protecting the CA keys is now the whole ballgame. A user CA in the clear on a workstation can mint access to every server that trusts it; a host CA can impersonate any host. Keep them passphrase-protected, on storage that is not online on the signing host, and back them up with the same care as any recovery secret (Chapter 15). Sign certificates in deliberate, short sessions; the validity windows make frequent re-signing cheap. Chapter 26 covers the same offline-CA discipline for TLS and the incident-response side of a suspected CA compromise.

20.3.4. FIDO2-Backed Keys, Touch Requirements, and Recovery Credentials

The keys so far live in files; copying the file copies the key. FIDO2 hardware authenticators - security keys speaking the WebAuthn protocols - move the private half of an SSH key into a device that will not export it. The key types are ed25519-sk and ecdsa-sk, and what is stored on disk is a key handle, not a private key: every authentication requires the device, and the device requires a touch.

Enrolling one needs hardware attached to the client. Without a device, the attempt fails exactly like this:

$ ssh-keygen -t ed25519-sk -C "john-fido2" -f ~/.ssh/id_ed25519_sk
Generating public/private ed25519-sk key pair.
You may need to touch your authenticator to authorize key generation.
Key enrollment failed: device not found

With an authenticator plugged in, the same command prompts for a touch (and, where configured, a PIN) and produces the key-handle file plus its .pub half, which installs in authorized_keys or signs into a certificate like any other public key. The server side needs no new configuration on a default Debian install: the sk- types are part of sshd's default PubkeyAcceptedAlgorithms; only hosts that explicitly tightened that list need to make sure they kept them.

The behavior worth planning around, from the FIDO2 design:

  • Touch on every use. By default each authentication requires a physical touch, witnessed by a blinking LED on the device. A stolen key handle cannot be used silently; a session that starts when the owner is absent fails. -O no-touch-required disables this at enrollment and should be used rarely and deliberately.
  • PIN entry. -O verify-required additionally asks for the device's PIN at each authentication, giving two factors (possession plus PIN) on the device itself.
  • Binding. The key handle is bound to the SSH application identifier, so a key enrolled for SSH is an SSH key, not a general WebAuthn credential, and it is bound to the individual authenticator.
  • Recovery. Because the private key cannot be exported, a lost or destroyed device means the credential is gone. Enroll a second authenticator's key alongside the first wherever the account matters, and keep one ordinary software key as a fallback path. -O resident stores a discoverable credential on the device itself, which ssh-keygen -K can download to a new machine - from the same authenticator; it is not a backup of the key, only a way to avoid carrying the key handle file.

Hardware-bound authentication is strongest when it is deliberate: a token per administrator, its keys in the same authorized_keys and certificate machinery as every other credential, and the recovery plan written down before the first token goes through the laundry.