How to create Sudo users in CentOS 7

Introduction

Sudo is the abbreviation of Super User Do. It is a command that enables programs to be implemented as a root user. Sudo runs commands provided to it with the privileges of a root user. It helps system administrators to grant specific users the permission to effectuate commands at the most powerful level (root level) without the need to log into the system as the root users.

This tutorial will help you create a unique user account in your CentOS system and grant it sudo privileges. It’ll also help you get started with sudo

Ready? Let’s get started!

Step 1 – Creating A New Sudo User

To create another  user in your CentOS  system, first run the command below to log into your server as a root user:

# ssh root@server_ip_address

Once you log in, execute the command below to create the new user:

# adduser hostadvice

The value hostadvice represents the name of the user you are about to create. Remember to replace this value with your desired username.

Next, execute the command below to set up the password for your newly created user:

# passwd hostadvice

This will give you a new output and you will be required to enter and retype the password for your new user. Make sure you have a strong password that combines letters, characters, and numbers.

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

Once you set up the password for this user, you can now execute the command below to add it to the CentOS wheel group.

# usermod -aG wheel username

By default, all users in the CentOS wheel group are given sudo access. For this reason, when you add the new user to the CentOS wheel group, you will automatically grant it sudo privileges.

Step 2 – Using Sudo in CentOS

By now, you have successfully created a new user and granted it sudo access. Next, you should grasp the basics to utilize sudo on CentOS with ease.

First, run the command below to  switch to your newly generated user:

$ su - hostadvice

Next, to utilize sudo you should prefix every command line with the sudo, followed by space. Run the command below to put the new user account to its first use:

$ sudo ls -l /root

Since this is the first instance you are using sudo on CentOS, you will get an output with the following message;

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for username:

Enter the password created in step one to continue. This will take you to the prompt of the newly created user. This prompt will be similar to:

[hostadvice@centos-s-1vcpu-1gb-tor1-01]$

If you want to execute any command as the root user, simply type exit and press ENTER, to exit the sudo account.

Conclusion

Congratulations! You have flawlessly created a new user and granted it sudo permissions on a CentOS server. If you want to create multiple sudo users on your Linux hosting (specifically, a VPS or dedicated server) follow all the steps for each user.

Remember to give a unique username and password for each user.

Check out these top 3 Linux hosting services

0

Was this article helpful?

Submit

Be the first to comment

Leave a Reply

Your email address will not be published.


*