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.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
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.

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.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.