Most sysadmins who manage several Linux servers end up with the same problem: an authorized_keys file on every machine, full of public keys nobody can explain. When someone leaves, or a laptop is stolen, you have to find every copy of their key and remove it. Keys also tend to live forever, so a single leaked private key is valid until someone notices.

SSH certificates fix this. Instead of trusting individual keys, each server trusts one certificate authority (CA). The CA signs short-lived user certificates, and a certificate is valid only until its expiry time. Revoking access means letting the certificate expire or removing one principal line, not hunting through config files. This guide is for sysadmins and self-hosters with a bastion host and a handful of Linux servers. You will set up the CA, issue time-limited certificates, lock down sshd, and verify each step.

Before you start

  • A bastion host (or any Linux server you can reach over SSH) running OpenSSH 7.x or newer. Current releases of OpenSSH support everything used here.
  • Root or sudo access on the bastion and on every target server.
  • A separate admin workstation to hold the CA private key. Do not keep the CA key on the bastion itself.
  • A working SSH login that you can keep open in a second terminal while you change sshd settings. Losing your only session during a config change is the most common self-inflicted outage.
  • Accurate system time on all machines (NTP or chrony). Certificate validity is time-based.

Step 1: Create the user CA on your admin workstation

On the admin workstation, create a directory for the CA and generate an Ed25519 key pair. Protect the private key with a strong passphrase when prompted.

mkdir -p ~/ssh-ca && chmod 700 ~/ssh-ca
ssh-keygen -t ed25519 -f ~/ssh-ca/user_ca -C user-ca-YOUR_DOMAIN
ls -l ~/ssh-ca

This creates user_ca (the private signing key, keep it secret) and user_ca.pub (the public key that servers will trust). Back up the private key somewhere encrypted and offline. If you lose it, you must redistribute a new CA public key to every server.

Step 2: Distribute the CA public key to your servers

Copy the public key to the bastion and each target server, then point sshd at it. The file is not secret, so mode 644 is fine.

scp ~/ssh-ca/user_ca.pub YOUR_ADMIN_USER@bastion.YOUR_DOMAIN:/tmp/user_ca.pub
ssh YOUR_ADMIN_USER@bastion.YOUR_DOMAIN 'sudo install -m 644 -o root -g root /tmp/user_ca.pub /etc/ssh/user_ca.pub'

Repeat for every server. Keeping the CA public key identical everywhere is what makes this scale: one signing key covers the whole fleet.

Step 3: Set up principal mapping

A certificate carries one or more principals, which are names it is allowed to log in as. You control which principals each local account accepts by writing an AuthorizedPrincipalsFile per user. On the bastion and each target server, create the directory and one file per account:

sudo mkdir -p /etc/ssh/auth_principals
echo 'alice' | sudo tee /etc/ssh/auth_principals/alice >/dev/null
sudo chmod 644 /etc/ssh/auth_principals/alice

The file lists the principals allowed to log in as that local user, one per line. Here, a certificate with principal alice can log in as the local account alice. Keep these files root-owned so users cannot add principals for themselves.

Step 4: Configure sshd to trust only the CA

Edit /etc/ssh/sshd_config on the bastion and each target server. Add or adjust these directives:

PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
TrustedUserCAKeys /etc/ssh/user_ca.pub
AuthorizedPrincipalsFile /etc/ssh/auth_principals/%u

What these do: TrustedUserCAKeys tells sshd to accept any user certificate signed by that CA. AuthorizedPrincipalsFile with %u maps each login name to its principal file. Disabling password and keyboard-interactive authentication removes the guessable credential path entirely. On older OpenSSH releases the keyboard option is named ChallengeResponseAuthentication.

Check the syntax before reloading, then reload. Do not restart sshd, because a reload keeps your existing sessions alive.

sudo sshd -t && echo 'config OK'
sudo systemctl reload sshd   # on Debian or Ubuntu the unit may be named ssh

If sshd -t reports an error, fix it before reloading. Keep your original session open until the new login works.

Step 5: Enable host certificates (recommended)

User certificates protect logins from the client side. Host certificates protect the client from connecting to an impostor server. Without them, users see host key prompts on first connect and may click through them. Create a separate host CA on the admin workstation, then sign each server’s host key:

ssh-keygen -t ed25519 -f ~/ssh-ca/host_ca -C host-ca-YOUR_DOMAIN
ssh-keygen -s ~/ssh-ca/host_ca -I bastion-host -h -n bastion.YOUR_DOMAIN,203.0.113.10 -V +52w /etc/ssh/ssh_host_ed25519_key.pub

Run the signing step on the server, after copying the host CA key over securely, or sign a copy of the host public key on the admin workstation and copy the resulting -cert.pub file back. Then add this line to sshd_config and reload:

HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub

On each client, trust the host CA once in ~/.ssh/known_hosts. Use a wildcard pattern for your domain. Paste in the key type and base64 body from host_ca.pub:

@cert-authority *.YOUR_DOMAIN ssh-ed25519 PASTE_HOST_CA_PUBLIC_KEY_BODY_HERE

Clients will now accept any server whose host key is signed by that CA and reject unsigned impostors.

Step 6: Issue a short-lived user certificate

On the admin workstation, sign a user’s public key. Keep the lifetime short. Eight hours covers a workday, and a few minutes is better for automation.

ssh-keygen -s ~/ssh-ca/user_ca -I alice-laptop-01 -n alice -V +8h -O clear -O permit-pty ~/.ssh/id_ed25519.pub

The flags matter. -I sets a key identity that appears in logs, so use something you can trace back to a device. -n alice sets the principal, which must match a line in the server’s principal file. -V +8h sets the validity window. -O clear drops all default extensions, then -O permit-pty adds back only the terminal option. Restricting extensions limits what the certificate can do.

This writes ~/.ssh/id_ed25519-cert.pub. OpenSSH loads it automatically when it sits next to the private key with the matching name, so ordinary ssh commands use it without extra flags. To renew access, sign the same public key again. The original public key does not change, so the user does not need to regenerate anything.

Step 7: Revoke access

Certificates are revoked by expiry, not by editing server files. For routine offboarding, remove the principal from the server so no new certificate for that user can log in:

sudo rm /etc/ssh/auth_principals/alice

Do this on every server, or push the change with your configuration management tool. Existing sessions may continue until they close, so terminate them if the person must lose access immediately. Because certificates expire in hours, you rarely need anything more. For a key or certificate you suspect is compromised, OpenSSH also supports a key revocation list (KRL) that you can reference with RevokedKeys in sshd_config. Generate it with ssh-keygen -k, and consult ssh-keygen(1) for your version’s exact options.

Verify it worked

Run these checks before you remove the old static keys.

  1. Confirm the effective config. On each server: sudo sshd -T | grep -Ei 'trustedusercakeys|authorizedprincipalsfile|passwordauthentication|permitrootlogin'. The output should show your CA file, the principal path pattern, and the disabled settings.
  2. Inspect the certificate. Run ssh-keygen -L -f ~/.ssh/id_ed25519-cert.pub. Check the key ID, principal, serial, and the valid-from and valid-to times.
  3. Log in with the certificate. Run ssh -v alice@bastion.YOUR_DOMAIN and confirm the login succeeds without a password prompt. In the debug output, look for the certificate being offered and accepted.
  4. Check the server log. Run sudo journalctl -u sshd -n 50 (or ssh on Debian-family systems). A successful certificate login logs the certificate type, key ID, serial, and CA fingerprint.
  5. Test expiry. Sign a certificate with -V +2m, wait for it to lapse, and confirm the login is refused.
  6. Test revocation. Remove the principal file for a test account and confirm a certificate for that account is refused, then restore it.

Common mistakes

  • Locking yourself out. Test the new config from a second session before closing the first. Keep a console or out-of-band access path for recovery.
  • Leaving password login enabled. Certificates do not protect a server that still accepts passwords. Verify that passwordauthentication reports no.
  • Storing the CA key on the bastion. A compromised bastion then yields the power to mint any login. Keep the CA key on a separate, locked-down admin machine, and set its permissions to 600.
  • Using long lifetimes. A 90-day certificate is a static key with extra steps. Keep validity to hours for interactive use.
  • Forgetting clock drift. A server clock several minutes off can reject fresh certificates or accept expired ones. Check time sync on every machine.
  • Skipping host certificates. Without them, users train themselves to accept host key warnings, which undermines the whole model.
  • Assuming principal names equal usernames. Without AuthorizedPrincipalsFile, sshd matches the principal to the login name. Be explicit with the file so behavior is predictable across servers.
  • Keeping the old authorized_keys files. Static keys still work if they remain in place. Once certificate logins are verified, remove or empty them, or set AuthorizedKeysFile to a path that no longer holds the old keys.

Takeaway

One CA, one trusted public key per server, and certificates that expire in hours replace a sprawling set of authorized_keys files. Offboarding becomes a single principal removal, and a stolen laptop’s credentials stop working on their own. Start with one target server, prove the flow with the verification steps above, and then roll out the same config across the fleet.