How to Create a Sudo User on CentOS

The sudo command gives a technique for providing trusted users with administrative permission to a Linux system without sharing the root user password.

When users permitted this technique precede an administrative command with sudo they are asked to provide their own password. Once login, and assuming the command is allowed, the administrative command is performed as if run by the root user.

Read Also: Difference Between su and sudo and How to Configure sudo in Linux

In this article, will show you how to create a new normal user account with sudo privileges on a CentOS system without having to change the system’s sudoers file.

Once sudo access granted, you can able to use the sudo command to run administrative commands without logging in to the root user account.

Create a New Sudo User on CentOS

1. Log in to your CentOS system as the root user.

$ ssh root@server_ip_address
Login into CentOS Server
Login into CentOS Server

2. Create a normal user account called tecmint using the useradd command, the -m option means to create the user’s home directory if it doesn’t exist, -s defines the new user’s login shell program (which is /bin/bash in this case) and -c defines a comment indicating that this is an administrative user account.

# useradd -m -s /bin/bash -c "Administrator" tecmint

Replace tecmint with the user name that you wish to create.

Create Sudo User in CentOS
Create Sudo User in CentOS

3. Set a password for the newly created user account using the passwd command (remember to set a secure strong password).

# passwd tecmint
Set Password for New User
Set Password for New User

4. On all Linux distributions that belongs to the RHEL family, only users in the wheel system group can run a command with sudo. So, next, add the new user tecmint to the wheel group using the usermod command. Here, the -a flag means to append user to a supplementary group and -G specifies the group.

# usermod -aG wheel tecmint
Add User to Wheel Group
Add User to Wheel Group

5. Test sudo access on newly created user account tecmint by invoking the su command to switch to the new user account and also verify that the user is in the wheel group.

# su - tecmint
$ groups
Switch User Account
Switch User Account

6. Now run the whoami command by prepending "sudo" to the command that you wish to run with administrative privileges.

$ whoami

As this is the first time you have executed sudo from this account the banner message will be shown. You will be also be asked to enter the password for the user account.

Run Sudo Command
Run Sudo Command

If sudo is configured correctly, the output of the above whoami command will show root.

7. You can also list the contents of the /root directory using the ls command, which is normally only reachable to the root user.

$ sudo ls -la /root
List Root Directory
List Root Directory

You might also like to read these following related articles on sudo.

  1. 10 Useful Sudoers Configurations for Setting ‘sudo’ in Linux
  2. How to Show Asterisks While Typing Sudo Password in Linux
  3. How to Keep ‘sudo’ Password Timeout Session Longer in Linux

That’s All! In this article, we’ve explained how to to create a new normal user account with sudo privileges on a CentOS system. For any questions, reach us via the comment form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.