As we mentioned in the previous post where we chose a VPS server, we ended up installing CentOS. When we complete the installation, it asks us for a password for our root user, which is the system's main user with access to everything. Therefore, I recommend changing the password to a very complex one, writing it down, and not using it again. Instead of using the root user, we will create one with administrator privileges.
What is the sudo command
The sudo command provides us a way to grant administrator privileges to users who are not the root
user. With these simple steps, you will see how to create sudo
users in CentOS without having to edit the sudoers file.
Steps to create a sudo user in CentOS
1 - Login to the server
The first thing to understand is that when we install a VPS, the system comes without a graphical interface, so we will access the server through the command line.
For this, we will use the only user we have (the root user), and to connect we will use PowerShell and the ssh command.
> ssh root@IP_SERVIDOR
Once we enter the password, we will be inside the VPS server.
2 - Creating a user in CentOS
Once logged in, we need to use the adduser
command to add a user. You need to replace NOMBRE_USUARIO
with the username you want to create.
# adduser NOMBRE_USUARIO
- We need to update the password for this new user with the
passwd
command.
# passwd NOMBRE_USUARIO
Set and confirm the new password, and you will see something similar to the following message.
Changing password for user NOMBRE_USUARIO
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
3 - Add user to the superuser group
To add a user to the sudo
group in CentOS, you only need to add them to the wheel
group using the usermod
command.
# usermod -aG wheel NOMBRE_USUARIO
-a
indicates we are adding to a group-G
specifies the list of groups; it's important to note that the letter G must be uppercase.
4 - Verify the superuser
We check that we have created the user and correctly added them to the superuser group. We need to switch our session to that user.
For this, we run the su
command
$ su - NOMBRE USUARIO
To check if we have sudo access, we can run a command that we normally would not have access to, such as the /root
folder
NOMBRE_USUARIO$ sudo ls /root
The first time you run a sudo
command, the system will ask for the password.
If everything worked correctly, you should see a list of files and folders contained in that directory.
If there is any problem you can add a comment bellow or contact me in the website's contact form