How to Create Sudo User on CentOS 7

How to Create Sudo User on CentOS 7

The sudo command is used to allow users to run programs with administrative privileges. The sudo stands for Super User DO. Sudo command temporarily elevates the privileges of a normal user for administrative tasks.

In today’s tutorial, we will learn how to create a new user with sudo privileges on CentOS. With a sudo user, we can perform administrative tasks on a Linux machine without the need to log n as the root user.

Creating Sudo User

CentOS 7 has a user group known as the wheel. All members of the wheel group are allowed to use the sudo command on CentOS. If you want to allow sudo privileges for an existing user, you need to add the user to the wheel group.

Follow the below steps to create a sudo user on the CentOS server.

Log into your server

Use the SSH command to log into the server with the root user.

ssh root@server_ip

Create a new user

Create a new user with the help of the useradd command.

useradd new_user

Set the password for the new user

Use the passed command to set a strong password for the newly created user.

passwd new_user
Setting up password for the newly created user

Adding the new user to the sudo group

Run the following command to add the newly created user to the sudo group, to grant sudo access.

usermod -aG wheel new_user

Alternative: Add User to Sudoers Configuration File

Open the Sudoers File in an Editor

Run the following command on the terminal to open the /etc/sudoers file in a text editor.

visudo

Add the New User to file

In the sudoers file, add the following lines.

new_user ALL=(ALL) ALL

Replace new_user with your newly created username. After adding the user, the sudoers file will look like this.

Adding new user in sudoers file.

Test Sudo Privileges for the User Account

Run the following command to switch to the newly created user.

su - new_user

It will ask for the password, Enter the password and press the Enter button.

Run the following command to list the contents of the “/” parent directory.

sudo ls -al /
List the contents of the parent directory

Conclusion

In today’s tutorial, we have learned how we can create a new user and assign the sudo privileges to the new user as well as to the existing user. Sudo command allows normal users to run programs with administrative privileges.

If you guys have any queries or questions, let me know in the comments section.