loader
August 12, 2021

How to Install and Manage Sudo

In this tutorial, we will show you How to Install and Manage Sudo on Debian and CentOS Servers

 
What is sudo And why would you use it?

The sudo command enables users to execute programs with the privileges of another user, typically the superuser. It originally stood for “superuser do” because older versions of sudo were designed to run instructions the most efficiently with the help of the superuser. Any Linux command can be run as the superuser with the sudo command. Say, for instance, you want sudo to have the right of entry to regulate a device document. you can exchange your user to the superuser in a shell using the su command.

How to Install and Manage Sudo?

Most Linux distributions come with the sudo package pre-installed.

To check whether the sudo package is installed on your system, open up your console, type “sudo” and press Enter. If you have sudo installed the system, will display a short help message. Otherwise, you will see something like sudo command not found.

Install Sudo on Debian 
 
apt-get install sudo -y
Install Sudo on CentOS
 
yum install sudo -y

 
How to Add Users to the Sudo Group
 

By default, on most Linux distributions granting sudo access is as simple as adding the user to the sudo group. Members of this group will be able to run any command as root. The name of the group may differ from distribution to distribution.

Debian / CentOS

Begin by adding the user account to the server if it does not already exist:

adduser newusername

Then you can add the user to the sudo or wheel group:

Debian

usermod -aG sudo newusername

CentOS

usermod -aG wheel newusername
 
Testing Sudo Access

You have now installed sudo and added the user to the sudo group. You can test sudo access by switching into the new user using the su command executing:

sudo echo "hi there"

You will be prompted to enter the password of the user, and the screen will display ‘hi there’ when executed successfully:

[email protected]:/root$ sudo echo "hi there"

hi there

If the user has not been added to sudo properly, it will display:

[email protected]:/root$ sudo echo "hi there"

User is not in the sudoers file. This incident will be reported

Using the sudo command and creating and managing new users with sudo privileges has been successfully completed.


That’s it

Get the most out of learning with VPSie.com