How to give a non-sudoer user the ability to run certain commands as root. Example a Web admin who needs the ability to restart or reload the web server service but wont be able to run any other commands as root.
Run:
sudo visudo -f /etc/sudoers.d/<name_of_file_you_want>
the -f switch is to create/specify a new sudoers file/location
From the example:
This will make a new file in the “/etc/sudoers.d” directory that you can add alias command groups that who ever you add to the group can run it as root
In the file the syntax is:
Cmnd_Alias <alias_name> = <full path of command> <command option> <argument>
<username> ALL=<alias_name>
You can specify multiple commands just separate them by a comma.
From the example:
Then save the file (esc -> :wq)
Now the user you added will be able to run that alias you specified as root and that is the only one they can run unless you add more. So from the example the user “gfreeman” can now run
“sudo systemctl restart httpd.service”
and
“sudo systemctl reload httpd.service”
Example learned from a lab at linuxacademy.com, in which i have rewritten from memory. (Or did but double checked myself.)