You need to onboard 50 new developers onto a shared build server, each with their own account and SSH key. How do you do it?
BeginnerScenarioUsers, groups and access control
Answer
Situation read → Bulk, repeatable user creation with consistent groups and key-only login.
What I'd do →
- Get a CSV of
username,pubkeyfrom the ticket. - Create a
developersgroup once:sudo groupadd developers. - Loop over the file:
while IFS=, read -r u key; do
sudo useradd -m -s /bin/bash -G developers "$u"
sudo install -d -m 700 -o "$u" -g "$u" /home/$u/.ssh
echo "$key" | sudo tee /home/$u/.ssh/authorized_keys >/dev/null
sudo chown "$u:$u" /home/$u/.ssh/authorized_keys
sudo chmod 600 /home/$u/.ssh/authorized_keys
done < users.csv
- Lock passwords (
passwd -l) since login is key-only, and verify withgetent group developers.
Why → Scripted creation avoids typos and wrong permissions that break key auth.
Interview tip → Say that beyond a handful of servers you would do this with Ansible's user and authorized_key modules, or central identity (LDAP/SSSD).
More on Users, groups and access control
Three teams share one server and each needs a project directory only its members can write to, with new files staying group-owned. How do you set it up?BeginnerA junior engineer needs to restart nginx but must not get full root. How do you grant that?BeginnerAn engineer leaves the company today. What do you do with their Linux account on 30 servers?BeginnerA service account for a backup tool must exist on every server but nobody should be able to log in as it. How do you create it?BeginnerYour security team requires passwords to expire every 90 days for human users only. How do you implement it?BeginnerTwo developers need read access to `/var/log/app/` without being added to the `adm` or root group. How?Intermediate