Key Rotation
procedureReplacing an existing SSH key with a new one, either on a planned schedule or in response to a security event. Keys don't expire on their own—SSH has no built-in expiration mechanism. A key generated in 2019 works identically in 2029. This is a feature—and a risk.
When to rotate.
Event-driven rotation (do it now):
- You suspect a private key was exposed
- A machine with your key was stolen or decommissioned
- You left a job and had keys on work machines
- You changed your security posture (moving from disk-based to hardware-backed)
Scheduled rotation (reasonable cadence):
- Disk-based keys: once a year is practical
- Hardware-backed keys: rotation is less urgent because the key cannot be copied, but rotating when you replace hardware is good practice
How to rotate. Rotation means:
- Generate a new key
- Deploy the new public key to all servers that need it
- Test access with the new key
- Remove the old public key from all servers'
authorized_keys - Delete or archive the old private key locally
The critical step is 3 before 4. Test before you revoke. Otherwise a mistake in deployment locks you out.