You must rotate the SSH key used by automation across 200 servers without locking yourself out. How?
AdvancedScenarioScenarios: deployments, user management and fleet operations
Answer
Situation read → Add before remove, verify before cleanup, and do it in batches.
What I'd do →
- Generate the new key:
ssh-keygen -t ed25519 -f ~/.ssh/automation_2026 -C automation-2026 -N ''. - Phase 1, add: append the new public key on every host (idempotent
grep -qxF || echo >>), using the old key. - Phase 2, verify:
ssh -i ~/.ssh/automation_2026 -o BatchMode=yes -o IdentitiesOnly=yes host trueon every host; collect failures and fix them. - Switch all automation (CI secrets, Ansible config) to the new key; run for a day.
- Phase 3, remove: delete the old key line with
sed -i "\|$(cut -d' ' -f2 old.pub)|d" ~/.ssh/authorized_keysusing the new key, again verifying access after. - Run each phase with
xargs -P 20and a log per host.
Why → At every point at least one working key exists, so a failure never strands a host.
Interview tip → Mention SSH certificates (a CA with short-lived certs) as the long-term fix that removes key rotation work.
More on Scenarios: deployments, user management and fleet operations
Write the core of a deploy script with release directories, an atomic symlink switch and rollback.IntermediateDeploy to 10 servers behind an AWS ALB one at a time, removing each from the target group during its deploy. Outline the script.AdvancedAfter a deploy, the health check fails intermittently. Your script must roll back automatically, but only if the failure persists. How?IntermediateImplement a blue/green switch on a single nginx host with a script.AdvancedOnboard 30 engineers: create accounts and install their SSH keys from their GitHub usernames, idempotently.IntermediateAn engineer leaves the company. Write the offboarding steps for Linux servers.Intermediate