As a system administrator, you may be familiar with sudo command. In this article, you will learn how to create a New Sudo-enabled user on CentOS 8. It provides a mechanism for granting administrator privileges — ordinarily only available to the root user to normal users.
In this tutorial, we are going to show you how to create a new user with sudo access on CentOS 8, without having to modify your server’s /etc/sudoers file.
Table of Contents
How to create a new Sudo-enabled user on CentOS 8
Let’s walk through the following steps to finish this guide. In case you consider to configure an existing CentOS user, skip to step 3.
Read more, if you are interested in:
initial set up centos 8
1- Logging into your server
First, SSH into your server as the root user. Replace your server’s IP address or hostname in place of the highlighted below.
ssh root@your_server_ip_address
2- Adding a New User to the System
You can use the adduser command to add a new user to your system and replace noodi with the username you’d like to create.
adduser noodi
Then, to update the new user’s password, use the passwd command.
passwd noodi
Do not forget to replace noodi with the user that you just created. Then you should answer twice for a new password.
Changing password for user noodi. New password: Retype new password: passwd: all authentication tokens updated successfully.
3- Adding the User to the wheel group
Next, to add the user to the wheel group, use the usermod command to add the user to the wheel group:
usermod -aG wheel noodi
While all members of the wheel group have full sudo access by default, make sure that you have replaced noodi with the username you’d like to give sudo privileges to.
4- Testing sudo access
In this step, you will see if the new sudo permissions are working or not. But to switch from the root user to the new user account, use the su command
su - noodi
Although you are a new user, you need to verify that you can use sudo by prepending sudo to the command that you want to run with superuser privileges.
sudo command_to_run
Also, you can list the contents of the /root directory, which is normally only accessible to the root user:
sudo ls -la /root
Once you begin to use sudo in a session, you will be asked to enter the password of that user’s account.
[sudo] password for noodi:
Please note: You should enter the sudo-enabled user password, not the root password. because it is not asking you for the root password.
Finally, you will see the command that you issued with sudo will run with root privileges, in case your user is in the proper group and you entered the password correctly.