This tutorial will guide you on how to assign a root privillege for users on RedHat 8.1 Linux server.
Sudo is installed by default on all environments. We can set a rules for an user to perform all the root actions or particular set of actions like service restart, specific command execution etc.,
1. Provide full root privileges to an user
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.
redhat ALL=(ALL) ALL
For an example, let's add redhat user into sudoers file to provide root access.
Example: Login as root from normal user
Execute sudo su - command to login as root from normal user.
[redhat@worldwidelinux ~]# sudo su -
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for redhat: {Type your user password}
[root@worldwidelinux ~]#
2. 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.
Example: 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
Restart httpd service as root from normal user.
[redhat@worldwidelinux ~]# sudo systemctl restart httpd.service
[sudo] password for redhat: {Type system user password}