SSH Key Rotation and Revocation Strategies for Production Systems
SSH Key Rotation and Revocation Strategies for Production Systems
SSH keys are not meant to live forever.
In real production systems, keys get:
- leaked
- shared accidentally
- forgotten
- compromised
This blog explains how to rotate and revoke SSH keys safely, without breaking access or deployments.
Why SSH key rotation matters
If a private key leaks:
- Anyone can authenticate as that user
- Access persists until the key is removed
- There is no password to reset
Key rotation limits damage.
Mental model: SSH keys are permissions
Think of each SSH key as:
“One permission token with no expiration.”
Your job is to:
- limit its scope
- rotate it periodically
- revoke it instantly when needed
Safe SSH key rotation (zero downtime)
Step 1: Add the new key (do NOT remove old yet)
cat new_key.pub >> ~/.ssh/authorized_keys
Now both keys work.
Step 2: Test with the new key
ssh -i new_key user@server
Confirm access.
Step 3: Update automation (CI/CD)
- Replace private key in GitHub Secrets
- Redeploy once
Step 4: Remove the old key
nano ~/.ssh/authorized_keys
Delete the old line.
Rotation complete.
Emergency revocation (key compromised)
- Remove the key from
authorized_keys - Kill active sessions (optional)
- Rotate any related credentials
pkill -u compromised-user
Best practices
- One key per purpose
- Comment keys clearly
- Rotate CI keys every 3–6 months
- Revoke immediately on suspicion
Final thought
SSH has no reset button.
Rotation is your reset button.
Related Posts
SSH Config Explained: How to Simplify Server Access with a Clean Laptop Setup
Learn how to use an SSH config file on your laptop to simplify server access, avoid mistakes, and connect to servers like LogicCraft with ease.
SSH Keys Deep Dive: Public vs Private, How Authentication Really Works
A practical deep dive into SSH keys—what public and private keys really are, how authentication works, and how to generate, store, and use keys safely.
SSH Keys Explained: Private Git Repos vs CI/CD Deployments (The Right Way)
A clear, practical guide to using SSH keys correctly for private Git repositories and CI/CD deployments without mixing trust models.