When our team grew past 30 engineers across 120 EC2 instances, key distribution broke down fast. Every onboarding meant syncing public keys across staging and production clusters. Offboarding was worse. If an engineer left and someone missed even one server’s ~/.ssh/authorized_keys, an orphaned key lingered indefinitely. We finally ditched static keys after an audit uncovered 47 stale keys scattered across our infrastructure. An OpenSSH Certificate Authority (SSH CA) solved the problem entirely.
The concept is straightforward. Rather than copying public keys to dozens of servers, you configure every target machine to trust a single CA public key. When an engineer needs access, the CA signs their public key into a certificate. That certificate defines permitted usernames and an exact expiration window. The target host validates the signature on connection, checks the clock, and lets the user right in.
Quick Start (5 Min): Setting Up Your First SSH CA
You can test this setup in five minutes between two VMs or directly on your workstation. The process requires three roles: the signing CA host, the target server, and the client machine.
Step 1: Generate the CA Keypair
Log into your designated CA machine. Keep this private key strictly isolated from public subnets:
# Create an isolated directory for CA keys
mkdir -p ~/ssh-ca && cd ~/ssh-ca
chmod 700 ~/ssh-ca
# Generate an Ed25519 keypair for the CA
ssh-keygen -t ed25519 -f ca_user_key -C "SSH User Certificate Authority"
This generates two files: ca_user_key (the private key you guard) and ca_user_key.pub (the public key your servers will trust).
Step 2: Configure the Target Server to Trust the CA
Copy ca_user_key.pub to your target server and store it in /etc/ssh/:
sudo cp ca_user_key.pub /etc/ssh/ca_user_key.pub
sudo chmod 644 /etc/ssh/ca_user_key.pub
Tell the SSH daemon to trust this CA key by updating /etc/ssh/sshd_config:
echo "TrustedUserCAKeys /etc/ssh/ca_user_key.pub" | sudo tee -a /etc/ssh/sshd_config
Verify your syntax before reloading the daemon. A typo here can lock you out:
sudo sshd -t && sudo systemctl restart sshd
Step 3: Sign a Client Key
Have an engineer generate their own standard SSH keypair on their laptop (ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519) and send you only their public key (id_ed25519.pub). Sign it on your CA host:
ssh-keygen -s ca_user_key \
-I [email protected] \
-z 1042 \
-n ubuntu,alice \
-V +8h \
id_ed25519.pub
Here is what these arguments mean:
-s ca_user_key: Signs the public key with the CA private key.-I [email protected]: Sets a unique key identity logged in/var/log/auth.logor journald.-z 1042: Assigns an incrementing serial number for tracking and revocation.-n ubuntu,alice: Restricts logins to these exact Linux user accounts (principals).-V +8h: Sets the certificate to expire eight hours from the moment of signing.
This generates id_ed25519-cert.pub in the same directory.
Step 4: Connect to the Server
Send id_ed25519-cert.pub back to the user. They must place it in their laptop’s ~/.ssh/ folder next to their private key. Connecting is seamless:
ssh -i ~/.ssh/id_ed25519 [email protected]
OpenSSH automatically detects the certificate file next to the private key. Authentication passes immediately, even if /home/ubuntu/.ssh/authorized_keys on the server is completely empty.
Deep Dive: How SSH Certificates Eliminate Key Sprawl
Standard SSH keys rely on static, symmetric trust. Every server keeps a flat file of allowed keys. Over months and years, those files collect ghost keys from departed contractors, reassigned developers, and forgotten CI pipelines. Verifying who holds access across 200 servers means running messy scripts against every host.
OpenSSH certificates replace that model with asymmetric trust, built directly into OpenSSH. An SSH certificate wraps an existing public key inside a structured envelope signed by the CA. During the initial handshake, the SSH daemon parses this metadata:
- Key ID: An audit identifier (such as an email address) written to syslog on every login attempt.
- Valid Principals: The explicit system accounts this certificate can access.
- Validity Window: Absolute UTC timestamps defining when access begins and ends.
- Options and Extensions: Granular permissions controlling PTY allocation, agent forwarding, and port forwarding.
Inspect any generated certificate using ssh-keygen:
ssh-keygen -L -f ~/.ssh/id_ed25519-cert.pub
The output shows the exact security boundaries baked into the cert:
~/.ssh/id_ed25519-cert.pub:
Type: [email protected] user certificate
Public key: ED25519-CERT SHA256:7uG9x1...
Signing CA: ED25519 SHA256:1aB4k9... (SSH User Certificate Authority)
Key ID: "[email protected]"
Serial: 1042
Valid: from 2026-11-24T08:00:00 to 2026-11-24T16:00:00
Principals:
ubuntu
alice
Critical Options: (none)
Extensions:
permit-X11-forwarding
permit-agent-forwarding
permit-port-forwarding
permit-pty
permit-user-rc
Because certificates expire in eight hours, offboarding is automatic. If an engineer loses their laptop at 6:00 PM, the certificate has already expired. You never have to scrub keys across your fleet under duress.
Advanced Usage: Expiration Windows, Principals, and Revocation
Enforcing Role-Based Principals
Do not let every engineer log in as root. You can map team roles directly to Linux system accounts using principal files.
On production database hosts, add this directive to /etc/ssh/sshd_config:
AuthorizedPrincipalsFile /etc/ssh/auth_principals/%u
Create the directory and define allowed roles for the dbuser account:
sudo mkdir -p /etc/ssh/auth_principals
echo -e "dba\nlead-sre" | sudo tee /etc/ssh/auth_principals/dbuser
Now only certificates bearing the principal dba or lead-sre can access dbuser. General developers holding certificates with the developer principal are rejected instantly.
Eliminating Host Verification Warnings
SSH CA works both ways. Signing server host keys eradicates the familiar prompt: “The authenticity of host ‘server.internal.net’ can’t be established.”
Create a dedicated Host CA keypair on your CA machine:
ssh-keygen -t ed25519 -f ca_host_key -C "SSH Host Certificate Authority"
Sign the server’s public host key, binding it to internal hostnames and IP addresses:
ssh-keygen -s ca_host_key \
-I prod-db-01.internal.net \
-h \
-n prod-db-01.internal.net,10.0.1.25 \
-V +52w \
/etc/ssh/ssh_host_ed25519_key.pub
On the server, register the signed host certificate in /etc/ssh/sshd_config and restart sshd:
HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub
Finally, configure user workstations to trust any host signed by your Host CA by adding this line to ~/.ssh/known_hosts:
@cert-authority *.internal.net,10.0.1.* ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG... (ca_host_key.pub content)
Clients connect to any matching server without interactive prompts or host-key mismatch warnings when instances get rebuilt.
Emergency Key Revocation with KRL
Short certificate lifetimes limit exposure, but compromised keys still require immediate action. If a private key leaks during its validity window, revoke it using an OpenSSH Key Revocation List (KRL).
# Initialize a new KRL or append a compromised cert
ssh-keygen -k -f /etc/ssh/revoked_keys.krl id_ed25519-cert.pub
# To add subsequent keys to an existing KRL, use the -u flag:
# ssh-keygen -k -u -f /etc/ssh/revoked_keys.krl compromised-cert.pub
Point sshd_config to your KRL:
RevokedKeys /etc/ssh/revoked_keys.krl
The server drops connections from revoked certificates immediately, even if their expiration timestamp remains valid.
Practical Rules for Production
- Keep your CA private key offline: Never host your root
ca_user_keyon an internet-facing machine. Run it on an encrypted, air-gapped machine or bind it to a hardware token like a YubiKey usingssh-keygen -t ed25519-sk. - Enforce 4 to 12 hour lifetimes: Avoid 30-day or 90-day certificates. For production, integrate with tools like HashiCorp Vault or Smallstep CA. Developers run a command like
step ssh login, authenticate against your IdP (Okta, Google Workspace), and receive a fresh 8-hour ticket for the workday. - Never mix user and host CAs: Maintain two separate keypairs:
ca_user_keyandca_host_key. Keeping them separated prevents an exploit in your user-signing pipeline from minting legitimate infrastructure host certificates. - Track serial numbers: Always use
-z serial_numberwhen signing certificates. Recording issued serials in an internal SQLite or PostgreSQL database makes auditing and targeted KRL revocations fast and error-free.

