Create a User with Sudo Permission on RHEL / CentOS

Last modified on February 18, 2020 47 sec read

On RHEL / CentOS server, the wheel group is granted with sudo. We can give sudo access to an existing user too. In this topic, we’re going to learn how to create a user and give permission to the user.

Table of Contents

  1. Create a New User
  2. Set User Password
  3. Provide Sudo Permission
  4. Test Sudo User

Create a New User

To create a user, we need to use the useradd command like this:

useradd theusername

Set User Password

To set user’s password, we need to run the passwd command:

passwd theusername

You’ll see the output like:

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

Provide Sudo Permission

We need to add the user to the wheel group:

usermod -aG wheel theusername

The user theusername has sudo permission now.

Test Sudo User

First, we need to switch to the newly created sudo user:

su - theusername

Now let’s run a sudo command:

# stucture
sudo [anycommand]

# example
sudo php -v

The first time, you’ll be asked to provide the user’s password.

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

The article is over. Thanks for reading. 🙂

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

Your email address will not be published. Required fields are marked *