authorized_keys files scattered across a fleet are the single most expensive secret to rotate. Every key that should have been removed years ago is still there, and every operator who leaves takes “do they still have access?” with them as an open question. The fix is to stop distributing public keys and start signing short-lived SSH certificates from a central authority. This article describes the model and the migration path.
How to verify
Get the truth about who can log in where, today:
sudo find /home /root -name authorized_keys -exec wc -l {} +
sudo ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub
sudo sshd -T | grep -iE 'trustedusercakey|authorizedkeysfile|authorizedprincipalsfile'
sudo grep -r '^TrustedUserCAKeys' /etc/ssh/
ssh -v user@host 2>&1 | grep -i 'cert\|fingerprint' | head
The find line is the inventory: every place a static key lives. The sshd -T query exposes whether the daemon trusts a CA at all, and which CA file.
What’s happening
SSH supports certificate-based authentication: a trusted certificate authority signs a short-lived certificate that asserts “this public key, for this principal, until this expiry”. The SSH server is configured with TrustedUserCAKeys /etc/ssh/ca.pub, and from then on any certificate signed by that CA authenticates the bearer — no authorized_keys entry needed.
Rotation becomes trivial: stop signing certificates for a user and they lose access in minutes (the lifetime of their last cert), not days. The CA is the only long-lived secret, and it lives in a vault (HashiCorp Vault, AWS Secrets Manager, an HSM, or an offline air-gapped key on a smartcard). Operators do not hold raw private keys for long — they hold a vault token and the workflow signs a fresh cert each morning.
The migration is staged. Hosts can trust both authorized_keys AND CA-signed certs simultaneously, which means you can roll out the CA-signing system, validate it for a week, then sweep authorized_keys files clean — with no flag day, no lost access.
The procedure
- Generate the CA. On the vault host,
ssh-keygen -t ed25519 -f /opt/ssh-ca/user_ca -C 'StackHarbor SSH user CA' -N ''. The private key never leaves the vault host; the public key is the trust anchor. - Distribute the CA public key to every server. With Ansible:
copy: src=user_ca.pub dest=/etc/ssh/ssh_user_ca.pub mode=0644. Then addTrustedUserCAKeys /etc/ssh/ssh_user_ca.pubto/etc/ssh/sshd_configand reload. - Configure principals. In
/etc/ssh/sshd_config, setAuthorizedPrincipalsFile /etc/ssh/principals/%u. Each file under/etc/ssh/principals/lists the principal names that may log in as that local user —ops,dev-team,ci-bot. A cert signed for principalopslets the bearer become any local user whose principal file listsops. - Sign a cert from the vault. With HashiCorp Vault’s SSH secrets engine:
vault write ssh-client-signer/sign/operator public_key=@~/.ssh/id_ed25519.pub valid_principals=ops ttl=8h. The output is a-cert.pubfile you save next to your private key. With ssh-keygen directly:ssh-keygen -s /opt/ssh-ca/user_ca -I 'alice-2026-06-02' -n ops -V +8h ~/.ssh/id_ed25519.pubproduces~/.ssh/id_ed25519-cert.pub. - The SSH client picks up the cert automatically when it sits next to the private key. Verify with
ssh -v user@host 2>&1 | grep -i 'Authenticating with certificate'. - Sweep static keys. After a week of dual-mode operation,
sudo find /home /root -name authorized_keys -exec mv {} {}.legacy \;on every host. A login that fails proves a missing principal mapping; fix it and continue. - Maintain a key inventory. The CA signs certs with a
key_idfield (the-Iflag) — make it the operator’s username and a date.ssh-keygen -L -f cert.pubprints every issued cert’s metadata. Pipe vault audit logs into a SIEM and the inventory writes itself. - Rotate the CA on a documented cadence. Generate a new CA, distribute the new public key alongside the old one, sign new certs from the new CA, then remove the old
TrustedUserCAKeysentry after the rollover.
Common pitfalls
- A signed cert with no
-V(validity) flag has no expiry — defeats the entire point. Always set-V +8hor shorter. - The
AuthorizedPrincipalsFiledirective only applies whenTrustedUserCAKeysis set; without principals, any cert signed by the CA authenticates as any user, which is too permissive. - ssh-agent forwarding does not forward certificates by default — pass
-O confirmand add the cert explicitly withssh-add ~/.ssh/id_ed25519-cert.pub. - Host certificates (signing the server’s host key) are a separate concern that solves the “yes/no” fingerprint prompt for users; they use
TrustedUserCAKeyson clients via@cert-authorityinknown_hosts. Worth doing in the same project. - Vault’s SSH secrets engine has an OTP mode that does not use certificates at all — confusing if you skim the docs. The CA mode is the one that scales.
In the engagements we run, SSH access is governed by short-lived certificates, with an audit trail in vault and a key inventory the security team can query without grep’ing a thousand hosts. That is part of Managed Operations — onboarding and offboarding stop being a migration each time.