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.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

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

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

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.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.