SSH Key Rotation
You perform ssh key rotation by creating new key pairs and removing old ones. Teams either update authorized keys files on every host or issue short-lived OpenSSH certificates. Most teams start by copying static public keys to server accounts. Over time, staff members change roles or leave the company. Old keys often stay on servers because no one tracks where they live. When shared accounts hold broad system rights, one forgotten key gives an attacker full control. How ssh key rotation works
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You perform ssh key rotation by creating new key pairs and removing old ones. Teams either update authorized keys files on every host or issue short-lived OpenSSH certificates. Most teams start by copying static public keys to server accounts. Over time, staff members change roles or leave the company. Old keys often stay on servers because no one tracks where they live. When shared accounts hold broad system rights, one forgotten key gives an attacker full control.
How ssh key rotation works in OpenSSH
Static key replacement follows a clear four-step path. First, an engineer or script makes a new public and private key pair. Second, the team adds the new public key to the server account file. Third, the user tests the new key to confirm that login works. Fourth, the team deletes the old public key from the server. This approach works on five hosts, but it breaks down across hundreds of machines.
To avoid touching every server during rotation, many teams switch to OpenSSH certificates. OpenSSH added certificate support for users and hosts in version 5.4. Instead of trusting individual user keys, each server trusts one Certification Authority key. The key generation tool signs a user public key with that authority key. The resulting certificate holds the public key, identity data, principal names, and login options. It uses a much simpler format than standard web TLS certificates. When you set a short validity window, the certificate expires on its own. You no longer need to scrub old public keys from every machine.
How to schedule and track key changes
Whether you rotate static files or sign certificates, you need a clear inventory. Start by listing every human key and every automated service account key. Service keys for build pipelines and backup jobs often break when changed by hand. Map each key to its owner and the exact hosts it reaches. Replace keys on one test server before you roll changes out to production.
Set a firm validity window when you sign user certificates. By default, OpenSSH certificates remain valid forever unless you set a time limit. Pick a window that matches one work shift or a single task. Keep the Certification Authority private key offline or locked inside a hardware module. Also plan for how you will rotate the authority key itself each year. You can place both old and new authority keys on hosts during the change.
SSH Key Rotation: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What key rotation solves and what it leaves open
Regular key rotation stops lost or stolen credentials from working forever. It shrinks the time window an attacker has if a laptop gets compromised. Certificate expiry also saves hours of manual cleanup when an engineer leaves a team. Your servers stay clean without constant file edits across your fleet.
Still, key rotation only checks who can start a login session. Once the server accepts the key or certificate, its job is done. It does not inspect or restrict the commands an engineer runs inside that shell. A valid user with broad Linux permissions can still drop tables or read secrets. Key files also cannot mask sensitive fields like emails or card numbers in terminal output. Standard server logs only record that a key logged in, not what happened next.
Check SSH commands and file transfers on the host
OpenSSH keys and certificates decide who can log into a Linux host. They do not check what a one-shot command or file transfer does once the session starts. With hoop.dev, you run an open-source SSH server with guardrails on the host. It checks callers with OpenSSH certificates and works with ssh, sftp, scp, and rsync clients.
When a caller runs a one-shot command or moves a file, hoop.dev guardrails check the command or path before it runs. Then hoop.dev data masking masks matched sensitive patterns in downloads and output. Interactive shells carry no guardrails because keystrokes have no statement boundary. Teams can turn interactive shells off and allow only commands and file tasks. The audit trail logs who connected and what was allowed or refused, without storing keystrokes or file bytes. See the source on GitHub.
Frequently asked questions
How often should teams run ssh key rotation?
For static keys, most security standards suggest rotating them every 90 days. You should also rotate keys right away when an engineer leaves the team. With OpenSSH certificates, you can issue credentials that expire after a few hours.
What is the difference between a static SSH key and an OpenSSH certificate?
A static SSH key is a raw key pair that never expires by itself. An OpenSSH certificate is a public key signed by a central authority key. It includes an identity, allowed user names, and a built-in expiration time.
Why do automated scripts break during ssh key rotation?
Scripts fail when a team deletes the old public key before updating the client. To prevent downtime, add the new public key to the server first. Update the script with the new private key, test it, and then remove the old key.
Related guides
In this post