How To Create a Sudo User on CentOS

Sudo 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. You can use the sudo user to perform administrative tasks on your CentOS Server without a need to logging in as the root 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 username

Replace username with the user name that you wish to create.

Setup password for the username

# passwd username

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

Add new user to wheel group

# usermod -aG wheel username

By default, all users in the CentOS wheel group are given sudo access.

In order to use Sudo user, switch to newly created user:

# su – username

To use sudo, simply prefix the command with sudo and space.

For example,

# sudo ls -l /root

Since this is the first time you are using sudo on CentOS, you will get an output as below:

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 for the new user. This will take you to the prompt of the newly created user:

[username@centos]$

That’s all.

By anup

Leave a Reply

Your email address will not be published. Required fields are marked *