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

An engineer leaves the company. Write the offboarding steps for Linux servers.

IntermediateScenarioScenarios: deployments, user management and fleet operations
Answer

Situation read → Revoke access immediately, preserve data for handover, and keep an audit trail.

What I'd do →

user=$1
id "$user" &>/dev/null || die "no such user $user"
usermod --lock --expiredate 1 --shell /usr/sbin/nologin "$user"    # no password, no login
pkill -KILL -u "$user" || true                                      # end sessions and processes
rm -f "/home/$user/.ssh/authorized_keys"
rm -f "/etc/sudoers.d/$user"
crontab -r -u "$user" 2>/dev/null || true
tar -czf "/var/backups/offboard/${user}-$(date +%F).tar.gz" -C /home "$user"
logger -t offboard "offboarded $user by ${SUDO_USER:-root}"
  1. Lock first, delete later (userdel -r after the retention period), so file ownership stays readable.
  2. Also revoke central access: IAM, SSO, VPN, Git hosting, CI secrets the person could read.

Why → Locking keeps UIDs stable for audit and data handover while removing access instantly.

Interview tip → Mention that SSH keys bypass a locked password, which is why removing authorized_keys matters.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: deployments, user management and fleet operations