How to allow specific commands or aliases
To allow specific commands or aliases, you need to add a line to the sudoers file that follows this format:
user host = (target) NOPASSWD: command
This means that the user can run the command as the target user on the host without entering a password. For example:
alice localhost = (root) NOPASSWD: /bin/systemctl restart apache2
This allows alice to restart the apache2 service as root on localhost without a password. You can also use aliases to group multiple commands or users. For example:
Cmnd_Alias WEB = /bin/systemctl restart apache2, /bin/systemctl reload nginx
User_Alias WEBMASTERS = alice, bob
WEBMASTERS localhost = (root) NOPASSWD: WEB
This allows alice and bob to run both commands as root on localhost without a password.