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 [email protected]_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.

Tutorial Feedback...
Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article...

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.