Contact Us:
CheapDeveloper » Webmaster » Articles » How to create a root user on CentOS

How to create a root user on CentOS

11 December 2021, Saturday By Priyanka Boruah


The sudo command (which stands for “substitute user and do”) allows a user to execute administrative commands that are usually only available to root users (or superusers). By following these instructions, you will easily learn how to create users that can execute these commands without having to modify the sudoers configuration files. If you are going to give sudo rights to an existing user, skip the first two steps and start right away with the third.

At the beginning of the command line, you will see the characters # and Username$ - you do not need to enter them! If you see #, execute the command on behalf of the superuser; if Username$, on behalf of the user you created.


Related: How to install Nginx on Ubuntu

Step 1 Login to your server as root user

local$ ssh root@server_ip_address

Step 2 Run the adduser command to create a new user on the system

(replace username with the name you want to give the new user)

# adduser username

Use the passwd command to assign a password for the created user:

# passwd username

Set and confirm a new password at the command line. I highly recommend coming up with a strong password!

Set password prompts:
Changing password for user username.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Step 3 Enter the usermod command to add the user to the wheel group

# usermod –aG wheel username

All users in this group have the ability to use the sudo command by default.

Step 4 Check if the new user has sudo rights.

For this:

  • Enter the su (change user) command to switch to the newly created user account:

# su – username

  • Write sudo before the command you want to run (command_to_run) as superuser.

Username$ sudo command_to_run

For example, you can request a list of the contents of the root directory /root - this information is usually only available to the root user.

username$ sudo ls -la /root

  • The first time you use sudo commands in a given session, you will be prompted for a password to log into that user's account. In order to continue, you need to enter your password.

[sudo] password for username:

If the user is in the correct group and you entered the password correctly, then the command you requested will be executed with administrative privileges.

Related: How to set up SSH keys and passphrase for your server


Read also:

Add a comment
Comments (0)