How to Create Sudo User on CentOS

Create Sudo User on CentOS

sudo is a Linux command which provides a mechanism for allowing administrator privileges to a normal user. In this tutorial, you are going to learn how to create sudo user on CentOS.


Before you start to create sudo user on CentOS. You must have the root user account credentials of your system.

Create a new sudo user

First Log in to the server as a root user.

ssh [email protected]_ip_address

Now to create a new user account we will use here, adduser command. To add new user run below command replacing NEW_USERNAME with the username you want to add.


After adding a new user you will need to set a password for it. to do so run following command in the terminal.


The output should look like:

Changing password for user username.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

To add newly created user to sudo group you should use usermod command.

usermod -aG sudo NEW_USERNAME

How to use sudo

Now to use sudo command you should first switch to the newly created user:


Now you can run any command with sudo privileges.
You can only use sudo account to display contents of root directory.

sudo ls -la /root

Now enter the password of the new user to get the list of files:

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 username:

After typing the correct password you will list root directory on your system.


You have successfully learned how to create sudo user on CentOS. If you have any queries regarding this then please don’t forget to comment below.