Onboard 30 engineers: create accounts and install their SSH keys from their GitHub usernames, idempotently.
IntermediateScenarioScenarios: deployments, user management and fleet operations
Answer
Situation read → GitHub publishes public keys at https://github.com/<user>.keys. The script must be safe to rerun.
What I'd do →
while IFS=, read -r user gh_user; do
[[ $user =~ ^[a-z_][a-z0-9_-]{0,31}$ ]] || { echo "skip invalid $user" >&2; continue; }
id -u "$user" &>/dev/null || useradd --create-home --shell /bin/bash --groups developers "$user"
install -d -m 0700 -o "$user" -g "$user" "/home/$user/.ssh"
keys=$(curl -fsS --max-time 10 "https://github.com/${gh_user}.keys") || { echo "no keys for $gh_user" >&2; continue; }
[[ -n $keys ]] || continue
tmp=$(mktemp); printf '%s\n' "$keys" > "$tmp"
install -m 0600 -o "$user" -g "$user" "$tmp" "/home/$user/.ssh/authorized_keys"; rm -f "$tmp"
done < <(tail -n +2 engineers.csv)
id -ucheck makesuseraddidempotent;installsets owner and mode atomically.- Validate usernames before using them in paths.
Why → Rerunnable scripts let you fix one bad row and rerun without side effects.
Interview tip → Mention that at scale this belongs in config management (Ansible user and authorized_key modules) or SSO with short-lived certificates.
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.AdvancedAn engineer leaves the company. Write the offboarding steps for Linux servers.IntermediateYou are asked to audit a server for risky accounts. What does your script check?Intermediate