A junior engineer needs to restart nginx but must not get full root. How do you grant that?
BeginnerScenarioUsers, groups and access control
Answer
Situation read → Least privilege through a narrow sudo rule.
What I'd do →
- Create a drop-in with
sudo visudo -f /etc/sudoers.d/nginx-ops:
%nginx-ops ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx, /usr/bin/systemctl reload nginx, /usr/bin/systemctl status nginx
- Add the user to
nginx-ops. - Test:
sudo -l -U aliceand have them runsudo systemctl reload nginx.
Why → Full paths and exact arguments stop the rule from being used to run arbitrary commands. visudo validates syntax so you can't lock yourself out of sudo.
Interview tip → Point out that granting sudo vim or sudo less is effectively root because they can spawn a shell.
More on Users, groups and access control
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?BeginnerThree 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?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