Interview Prep/Linux/Users, groups and access control

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 →

  1. 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
  1. Add the user to nginx-ops.
  2. Test: sudo -l -U alice and have them run sudo 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.

All Linux questions Roadmap: Linux

More on Users, groups and access control