>_ IzzyLab

Hands-on task

This task is step 18 of the course “Users, groups and permissions”

Set up passwordless sudo for deploy

medium~7 min

The CI user deploy needs to restart the service without an interactive password, but full root cannot be given to it. Via sudoers, allow the deploy user to run only /usr/bin/systemctl restart app (and nothing else) without a password.

What you'll practise:
  • sudo
  • sudoers.d
  • visudo
  • principle of least privilege
  • NOPASSWD

Topic breakdown

The principle of least privilege: a user is given exactly the one command needed, not root as a whole. sudo rules are placed as a separate fragment in the /etc/sudoers.d/ directory rather than editing the shared file by hand. A rule line describes who, on which hosts, as whom, and what exactly may be run; the tag before the command removes the password prompt, and the command is given with its full path and exact arguments. A corrupted sudoers can lock out sudo entirely, so the syntax must always be checked with a validator (visudo -c).

What's checked

  1. sudoers configuration is valid
  2. deploy can run systemctl restart app without a password
  3. deploy's rights are limited to one command

What it looks like