This tutorial is out of date and no longer maintained.
Please refer instead to our updated quickstart tutorial, How To Create a New Sudo-enabled User on CentOS 8.
sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users. This guide will show you the easiest way to create a new user with sudo access on CentOS, without having to modify your server’s
sudoers file. If you want to configure sudo for an existing user, simply skip to step 3.
Log in to your server as the
- ssh root@server_ip_address
adduser command to add a new user to your system.
Be sure to replace username with the user that you want to create.
- adduser username
passwd command to update the new user’s password.
- passwd username
Set and confirm the new user’s password at the prompt. A strong password is highly recommended!
Set password prompts:Changing password for user username. New password: Retype new password: passwd: all authentication tokens updated successfully.
usermod command to add the user to the
- usermod -aG wheel username
By default, on CentOS, members of the
wheel group have sudo privileges.
Test sudo access on new user account
su command to switch to the new user account.
- su - username
As the new user, verify that you can use sudo by prepending “sudo” to the command that you want to run with superuser privileges.
- sudo command_to_run
For example, you can list the contents of the
/root directory, which is normally only accessible to the root user.
- sudo ls -la /root
The first time you use
sudo in a session, you will be prompted for the password of the user account. Enter the password to proceed.
Output:[sudo] password for username:
If your user is in the proper group and you entered the password correctly, the command that you issued with sudo should run with root privileges.
Here is a link to a more detailed user management tutorial:
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up