How To Add User to Sudoers on CentOS 7

How To Add User to Sudoers on CentOS 7

On this short article, we will learn how to add an regular user to be sudoers on CentOS 7 opearting system.

Introduction

Sometimes we need root level privileges to run some tasks in an operating system, in this case CentOS 7. For this purpose, the operating system has provided a facility known as sudo. The sudo command stands for “Super User DO” and temporarily level up the privileges of a regular user for administrative tasks. In this article, we will discuss how to add a regular user to sudoers.

Prerequisite

  • CentOS 7 system
  • Root user or regular user who already has sudo privileges

Adding New User To sudo Group

CentOS 7 has a user group called the “wheel” group, where the members of this group are automatically granted sudo privileges. We will add a new user to this group to grant sudo privileges to that user. For this purpose we will do the following tasks.

Verify the ‘wheel’ group is enabled

For the first time, we have to verify if the wheel group is enabled. For this purpose we will submit the following command line:

$ visudo

We will be entering to /etc/sudoers file, then find and remove the ‘remarks sign’ on the left side.

## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL

to be :

%wheel ALL=(ALL) ALL

Add New User to wheel Group

To add a new user to wheel group, we will submit the command line :

$ usermod –aG wheel UserName

Adding New User To Sudoers Configuration File

To ensure, a new user having sudo privilege, we have to add to sudoers configuration file.

  1. Submit $ visudo command line.
  2. Add new user to sudoers configuration file
## Allow root to run any commands anywhere

root ALL=(ALL) ALL
ramansah ALL=(ALL) ALL

On this tutorial, we will add a new user called as ‘ramansah’ to the file.

visudo
visudo

Testing sudo Privilege

After all are set, then we will test a new user to do the root account can do.

[ramansah@localhost /]$ sudo ls -ltr /root
total 8
-rw-------. 1 root root 1758 Jul 28 20:27 anaconda-ks.cfg
-rw-r--r--. 1 root root 1786 Jul 28 20:40 initial-setup-ks.cfg

It works, running properly.

Conclusion

On this short tutorial, we have shown you how to add a new user to a sudoers group on CentOS  7 operating system.

(Visited 62 times, 1 visits today)

You may also like