This tutorial will guide you on how to assign an user to perform particular tasks with root privillege and without entering root password on RedHat 8.1 Linux server.
1. Allow users to perform root actions
Open terminal and login as root user, then open sudoers file using vim editor.
[root@worldwidelinux ]# vim /etc/sudoers
Add below line into sudoers file on 101th line.
user_name ALL=(ALL) ALL=systemctl restart httpd.service
Replace user_name with your username. You can add multiple commands seperated by comma in the ALL= attribute.
2. Restart a httpd service as root user
For an example, we allow redhat user to perform httpd restart. Usually, root user only can do service start, stop and restart actions. So we have to configure redhat user to perform a systemctl restart command into sudoers file.
redhat ALL=(ALL) ALL=/usr/bin/systemctl restart httpd.service
[redhat@worldwidelinux ~]# sudo systemctl restart httpd.service
[sudo] password for redhat: {Type system user password}