Interview Prep/Shell Scripting/Scenarios: deployments, user management and fleet operations

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 →

  1. Generate the new key: ssh-keygen -t ed25519 -f ~/.ssh/automation_2026 -C automation-2026 -N ''.
  2. Phase 1, add: append the new public key on every host (idempotent grep -qxF || echo >>), using the old key.
  3. Phase 2, verify: ssh -i ~/.ssh/automation_2026 -o BatchMode=yes -o IdentitiesOnly=yes host true on every host; collect failures and fix them.
  4. Switch all automation (CI secrets, Ansible config) to the new key; run for a day.
  5. Phase 3, remove: delete the old key line with sed -i "\|$(cut -d' ' -f2 old.pub)|d" ~/.ssh/authorized_keys using the new key, again verifying access after.
  6. Run each phase with xargs -P 20 and 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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: deployments, user management and fleet operations