The sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users.
There is a SuperUser named root. The root user can do anything and everything, and thus doing daily work as the root can be very dangerous. You could type a command incorrectly and destroy the system. The sudo command allows a permitted user to run a command as the superuser (root user) or another user, as specified by the security policy. Often the sudo used on servers to give admin permissions and privileges to ordinary 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.
Note: If you want to configure sudo for an existing user, kindly skip to step number 4.
Create a New Sudo User on CentOS
1. Log in to your server as the root user.
2. Use useradd command to add a new user.
Note: replace username with the user that you want to create.
3. Use the passwd command to create a new password to user you have been created.
Set the new user’s password . A strong password highly recommended.
4. Use the usermod command to add the user to the wheel group.
usermod -aG wheel username
Note: On CentOS, members of the wheel group have sudo privileges.
5. Test sudo privileges on new user account
- Use the
sucommand to switch to the new user account.
su - username
Verify that you can use sudo by running sudo to the command that you want to run with superuser privileges.
sudo ls /
Note: The first time you use sudo in a session, The password will be required for the new user . Enter the password to proceed as shown above in the screenshot.
In this tutorial we illustrated you how to create sudo user on CentOS, we created a new user account and added it to the sudo group to enable sudo access.