SSH Certificates & Bastion Hosts
With plain keys, every server keeps an authorized_keys list per account, and every client keeps a known_hosts list of server keys it has learned by "trust on first use". With 5 servers that is fine. With 500 servers and 40 engineers, adding a person means touching 500 files, removing one means hoping you found every copy, and every new server greets people with "The authenticity of host … can't be established", which everyone learns to answer with yes without reading.
SSH certificates replace both lists with one trusted signer. A certificate authority (just another key pair) signs users' public keys ("this key belongs to ada, may log in as ada and deploy, until Friday") and servers' host keys ("this is web1.example.com"). Servers trust the user CA; clients trust the host CA. This is OpenSSH's own format, not X.509.
Signing a user certificate
ssh-keygen -q -t ed25519 -N "" -C "TAD user CA" -f user_ca # keep this one offline / in a vault
ssh-keygen -q -t ed25519 -N "" -C "ada@laptop" -f id_ed25519 # Ada's normal key
ssh-keygen -s user_ca -I "ada@example.com" -n ada,deploy \
-V 20260115:20260116 -z 1001 id_ed25519.pub
ssh-keygen -L -f id_ed25519-cert.pub | sed 's/SHA256:.*/SHA256:…/'Signed user key id_ed25519-cert.pub: id "ada@example.com" serial 1001 for ada,deploy valid from 2026-01-15T00:00:00 to 2026-01-16T00:00:00
id_ed25519-cert.pub:
Type: ssh-ed25519-cert-v01@openssh.com user certificate
Public key: ED25519-CERT SHA256:…
Signing CA: ED25519 SHA256:…
Key ID: "ada@example.com"
Serial: 1001
Valid: from 2026-01-15T00:00:00 to 2026-01-16T00:00:00
Principals:
ada
deploy
Critical Options: (none)
Extensions:
permit-X11-forwarding
permit-agent-forwarding
permit-port-forwarding
permit-pty
permit-user-rc
| Flag | Meaning |
|---|---|
-s user_ca |
sign with this CA key |
-I |
key ID: appears in the server's log for every login with this certificate, so make it identify the person |
-n ada,deploy |
principals: the account names this certificate may log in as |
-V 20260115:20260116 |
validity window; short lifetimes (hours) replace revocation in practice. -V +8h means "from now for 8 hours" |
-z 1001 |
serial number, for revocation lists |
-O |
options: -O clear -O permit-pty removes the default permissions and grants back only a terminal; -O source-address=10.0.0.0/8 |
Ada keeps her private key; she only receives id_ed25519-cert.pub next to it, and ssh picks it up automatically.
Telling the server to trust the CA
# /etc/ssh/sshd_config.d/20-ca.conf
TrustedUserCAKeys /etc/ssh/user_ca.pub
AuthorizedPrincipalsFile /etc/ssh/principals/%uTrustedUserCAKeys makes sshd accept any certificate signed by that CA whose principals include the target account. AuthorizedPrincipalsFile changes the rule to "the certificate must carry one of the principals listed in /etc/ssh/principals/<account>", so /etc/ssh/principals/deploy containing deploy and oncall lets several roles in, without any authorized_keys. Checked with the session's own sshd:
ssh-keygen -q -t ed25519 -N "" -f hostkey
ssh-keygen -q -t ed25519 -N "" -C "TAD user CA" -f user_ca
mkdir -p principals && printf 'deploy\noncall\n' > principals/deploy
cat > sshd_config <<EOF
HostKey $PWD/hostkey
PidFile $PWD/sshd.pid
TrustedUserCAKeys $PWD/user_ca.pub
AuthorizedPrincipalsFile $PWD/principals/%u
AuthorizedKeysFile none
PasswordAuthentication no
EOF
sshd -t -f sshd_config && echo "syntax OK"
sshd -T -f sshd_config | grep -E '^(trustedusercakeys|authorizedprincipalsfile|authorizedkeysfile) ' | sed "s#$PWD#/etc/ssh#"syntax OK
trustedusercakeys /etc/ssh/user_ca.pub
authorizedprincipalsfile /etc/ssh/principals/%u
authorizedkeysfile none
AuthorizedKeysFile none switches plain keys off entirely: only certificates get in.
Host certificates: no more "authenticity can't be established"
The same CA idea works the other way round. A host CA signs each server's host key with its names (-h makes a host certificate), and clients trust the CA with one line in known_hosts:
ssh-keygen -q -t ed25519 -N "" -C "TAD host CA" -f host_ca
ssh-keygen -q -t ed25519 -N "" -f ssh_host_ed25519_key # web1's host key
ssh-keygen -s host_ca -h -I web1 -n web1.example.com,web1,10.0.0.21 \
-V 20260101:20270101 ssh_host_ed25519_key.pub
ssh-keygen -L -f ssh_host_ed25519_key-cert.pub | grep -E -e Type -e 'Key ID' -e Principals -A3 | grep -v -e Critical -e '^--' -e SHA256 -e Serial -e Valid
echo "@cert-authority *.example.com,10.0.0.* $(cut -d' ' -f1,2 host_ca.pub)" > known_hosts
cut -c1-60 known_hostsSigned host key ssh_host_ed25519_key-cert.pub: id "web1" serial 0 for web1.example.com,web1,10.0.0.21 valid from 2026-01-01T00:00:00 to 2027-01-01T00:00:00
Type: ssh-ed25519-cert-v01@openssh.com host certificate
Key ID: "web1"
Principals:
web1.example.com
web1
10.0.0.21
@cert-authority *.example.com,10.0.0.* ssh-ed25519 AAAAC3Nza
On the server, HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub presents the certificate. Every client with that @cert-authority line then trusts web1 (and every future server the CA signs) without a prompt, and a man-in-the-middle with an unsigned key triggers a hard error instead of a question.
Revocation
Short-lived user certificates mostly expire before revocation matters. For long-lived ones and for lost keys, OpenSSH has key revocation lists (KRL), set with RevokedKeys /etc/ssh/revoked.krl in sshd_config:
ssh-keygen -q -t ed25519 -N "" -f user_ca
for who in ada ben; do
ssh-keygen -q -t ed25519 -N "" -f "$who"
ssh-keygen -q -s user_ca -I "$who" -n "$who" -V 20260101:20270101 -z $([ $who = ada ] && echo 1 || echo 2) "$who.pub"
done
echo "serial: 2" > revoke.txt # Ben's laptop was stolen
ssh-keygen -q -k -f revoked.krl -s user_ca.pub revoke.txt
ssh-keygen -Q -f revoked.krl ada-cert.pub ben-cert.pub
echo "exit code: $?"ada-cert.pub (learner@tad): ok
ben-cert.pub (learner@tad): REVOKED
exit code: 1
ssh-keygen -Q checks keys against the list: ok for Ada, REVOKED for Ben, and a non-zero exit code when anything is revoked, which suits a check script.
Bastion hosts and the tools around them
A bastion (jump host) is the only server reachable by SSH from outside; everything else accepts SSH only from the bastion's address (a firewall rule or Match Address). Clients reach inner servers with ProxyJump (SSH Keys & ssh-agent). Keep the bastion minimal: no other services, no agent forwarding, AllowTcpForwarding only as far as ProxyJump needs, and its logs shipped elsewhere.
You rarely run your own CA by hand for long. Common setups:
| Approach | What it gives you |
|---|---|
| HashiCorp Vault / OpenBao SSH secrets engine | signs short-lived certificates after the user logs in to Vault |
| step-ca (Smallstep) | SSH and X.509 CA with SSO login (step ssh login) |
| Teleport, Boundary | access proxies with SSO, session recording, per-request approval |
| AWS SSM Session Manager, GCP IAP, Azure Bastion | no inbound SSH port at all; access through the cloud provider's IAM |
The common goal: no long-lived keys on laptops, logins tied to an identity provider, and an audit trail.
Test yourself
What problem do SSH user certificates solve?
- They encrypt traffic better
- Servers trust one CA instead of maintaining authorized_keys lists, and access can be time-limited and tied to principals
- They replace passwords with PINs
- They remove the need for private keys
In ssh-keygen -s ca -I ada@example.com -n deploy -V +8h key.pub, what are -n and -I?
- Hostname and IP
- -n: the principals (accounts) the certificate may log in as; -I: the key ID written to the server logs
- Serial and issuer
- Number of logins and interval
What does an @cert-authority *.example.com ssh-ed25519 … line in known_hosts do?
- Revokes keys
- Trusts any host certificate signed by that CA for matching host names, so new servers don't prompt
- Disables host key checking
- Adds a user CA