Linux Users need root or administrative privileges to install new software on a system through the command line. When a new user creates an on a Linux system, you grant some Sudo privileges to run administrative commands. The 'sudo' command access allows trusted users to execute the administrative commands as another user. So, you can grant some specific privileges and add these trusted users in a sudoers group or a file.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Sudo queries on Linux Systems.
In this context, we shall look into how to add a user to sudoers using the terminal on the Debian 10 system.
Methods of adding a user to sudoers using the terminal on the Debian
There are two ways to add a user to sudoers : you can add this user to the sudo group or you can add this user to the sudoers file located at etc.
1. Add User to a Sudoers Group on Debian
The most frequently used method to assign sudo privileges to a user is to add a user into the sudoers group. The members of the sudoer group can run all administrative commands as root. When a command runs with sudo privileges, a password confirmation prompt shows on the terminal. The sudo user authenticates this process using the password.
You can add an existing user into the sudoers group or if you want then create a new user and add this user into the sudoers group. Here, we assume that a user is already created. So, add this already existing user into the sudoers group by using the below-mentioned syntax:
$ usermod -aG sudo user_name
In the above command, sudo is the group name and user_name is the name of the user. For example, we are adding a user named 'linuxapt' into the sudoers group. Therefore, the above command will change into the following form:
$ usermod -aG sudo linuxapt
The above-explained method is enough for granting sudo privileges to a user. To verify that the user is now added into the sudoers group, type the following terminal command:
$ sudo whoami
Now Enter the password. If the user is added into the sudoers group then, the 'root' will display in the result. Otherwise, it will display an error on the terminal screen.
2. Add user into the sudoers file
All sudo and group rules are defined into the sudoers file that you can locate at '/etc/sudoers' location in your system. In this file, we define certain rules and set of the privileges which we assigned to a particular user.
Using two different approaches you can grant access to a sudo user. Either, you can configure the '/etc/sudoers' file on your system and edit it or you can create a new file in the '/etc/sudoers.d' directory. To modify the sudoers file, type the below-mentioned command:
$ sudo visudo
Now, at the end of the configuration file add the following rules as follows:
user_name ALL=(ALL) NOPASSWD:ALL
Change the user name with your user.
How to Allow Limiting command access to sudo user ?
You can also give some limiting sudo privileges to a user. For example, we want to grant specific privileges of 'useradd' and 'adduser' commands to the user 'linuxapt'.
linuxapt ALL=(ALL) NOPASSWD: /usr/sbin/useradd,/usr/sbin/adduser
Save the above-explained rules at the end of the sudoers file. After that, the user can only run the 'adduser' and 'useradd' commands.
You can also create a new file in the '/etc/sudoers.d' directory and define some set of rules.
[Need help in Installing Open Source Software on Linux System? We can help you. ]