How to create a superuser in CentOS

23 Dec 2019 5 min See Original (spanish)

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.

This post was translated from Spanish. You can see the original one here.
If there is any problem you can add a comment bellow or contact me in the website's contact form

Uso del bloqueador de anuncios adblock

Hola!

Primero de todo bienvenido a la web de NetMentor donde podrás aprender programación en C# y .NET desde un nivel de principiante hasta más avanzado.


Yo entiendo que utilices un bloqueador de anuncios como AdBlock, Ublock o el propio navegador Brave. Pero te tengo que pedir por favor que desactives el bloqueador para esta web.


Intento personalmente no poner mucha publicidad, la justa para pagar el servidor y por supuesto que no sea intrusiva; Si pese a ello piensas que es intrusiva siempre me puedes escribir por privado o por Twitter a @NetMentorTW.


Si ya lo has desactivado, por favor recarga la página.


Un saludo y muchas gracias por tu colaboración

© copyright 2025 NetMentor | Todos los derechos reservados | RSS Feed

Buy me a coffee Invitame a un café