Add User to the Wheel Group in CentOS

Give a user sudo access to run sudo command.

Add User to the Wheel Group in CentOS

The wheel group is a special user group that allows all members in the group to run all commands. Therefore, you need to add the new user to this group so it can run commands as superuser. You can do that by using the following command:

# usermod -aG wheel newuser

Again, make sure you are using the name of the actual user instead of newuser.
Now, use visudo to open and edit the /etc/sudoers file. Make sure that the line that starts with %wheel is not commented. It should look exactly like this:

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

Now that your new user is set up you can switch to that user and test if everything is OK.

5. Switch to the sudo User

To switch to the new user, run the following command:

# su - newuser

Now run a command that usually doesn’t work for regular users like the one below:

$ ls -la /root/

You will get the following error message:

ls: cannot open directory /root/: Permission denied

Try to run the same command, now with using sudo

$ sudo ls -ls /root/

You will need to enter the password for the new user to proceed. If everything is OK, the command will list all the content in the /root directory. Another way to test this is to run the following command:

$ sudo whoami

The output of the command should be similar to the one below:

$ sudo whoami
root

Leave a Reply

Your email address will not be published.