Read in 2 minutes

last updated 

How To Create a Sudo User on CentOS

This tutorial is also available for:

debian ubuntu

The sudo command is designed to allow users to run programs with the security privileges of another user, by default the root user. In this guide we will show you how to create a new user with sudo privileges on CentOS.

How to create a sudo user

By default on CentOS, users in the group wheel are granted with sudo access. Follow this steps to create a sudo user on your CentOS server. If you want to configure sudo for an existing user, skip to step 4.

  1. Log in to you CentOS server as the root user:

    ssh [email protected]_ip_address
  2. Create a new user account using the useradd command:

    useradd username

    Replace username with the user name that you want to create.

  3. Use the passwd command to set a password for the new user:

    passwd username
    Changing password for user username.
    New password:
    Retype new password:
    passwd: all authentication tokens updated successfully.
  4. Add the new user to the wheel group.

    usermod -aG wheel username
Advertisement

How to use sudo

Switch to the newly created user:

su - username

To use sudo, simply prefix the command with sudo and a space.

sudo ls -l /root

The first time you use sudo from this account, you will see the following banner message and you will be prompted to enter the password for the user account.

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:

Conclusion

That’s all. You have successfully created a sudo user on your CentOS system. You can now use this user to perform administrative tasks on your server.

Feel free to leave a comment if you have any questions.