In Linux, a user who has been granted the ability to execute commands with superuser privileges is known as a “sudoers”. This allows them to perform tasks that require elevated privileges, such as installing software, modifying system configuration, and managing system services.
To become a sudoers, a user must typically be added to the “sudo” group or be listed in the /etc/sudoers file. When executing a command with sudo, the user is prompted for their password to confirm their identity and authorize the command.
This post discusses possible methods to add a user to sudoers in Debian (one of the most used Linux-based operating systems).
Approach #1: Using the chmod Command
Now, what practically does adding a user to sudoers means? We have a user named “linuxgenie”. Let’s update the system using this user’s account.
$ sudo apt update
The output has thrown an error that the user is not in the sudoers group, which means the “linuxgenie” cannot use sudo. Simple procedural steps are provided below to add this user to the sudo group.
Step 1: The “chmod” command with the following syntax is used to add a user to a sudo group.
$ usermod -aG sudo <username>
The “usermod” is the commands keyword, while the “a” shows the add, and the “G” represents the group. After that, the group name comes (sudo in this case) and the username. The username is “linuxgenie” in our case, so the command below will add it to the sudoers group.
$ sudo usermod -aG sudo linuxgenie
Note: Ensure that the command is run as a root user or user with sudo privileges.
Step 2: Once the user is added, test the addition by running a sudo command through the “linuxgenie” user. Before that, make sure you are switched to a user account for which you are doing the testing, and in this case, it is “linuxgenie”. Here, we are upgrading the packages list.
$ sudo apt upgrade
The command is executed, which shows the user has been successfully added to the group.
Approach #2: Through the “/etc/sudoers” File
The “/etc/sudoers” file also contains the users that have the sudo privileges. A user can directly be added to it to have sudo privileges. We have a user named “genieuser”, which will be added to this file.
Step 1: Open the file with editing privileges with the following command.
$ sudo nano /etc/sudoers
Step 2: Now, add a line with the following syntax at the end of the file.
$ username ALL=(ALL: ALL) ALL
In our case, the username is “genieuser”, and the added line is shown in the screenshot below.
Once done, save the file, and the “genieuser” can now be used with the sudo keyword.
Approach #3: From System Settings
One can add the user to sudoers from the System settings of the Debian systems. There are two possibilities while using this method: an existing user needs to be added to sudoers or a new user. Both scenarios are discussed here.
Part 1: Add an Existing User to Sudoers
The steps demonstrated below will guide to add an existing user to sudoers.
Step 1: Open the system settings by searching the keyword “Settings” in the applications menu.
Step 2: Open the “Users” tab and click on the user not added to the sudoers. (the toggle button will be turned off in front of the user). In our case, it is “genie”, as shown below.
Now, turn on the toggle button in front of that user.
Step 3: Scroll down and click on the “Password” option.
A new window will appear where the password needs to be inserted. For this, click the “Set a password now” and click on the “Change” option.
Part 2: Create and Add a New User to Sudoers Group
To create and add a new user to sudoers, follow the steps.
Step 1: Open the system settings and click the “Users” option. Then, go to the “Unlock” option.
Enter the user password.
Step 2: Now, navigate to the “Add User…” option/button.
Add Account Information
Set the Account Type to Administrator. Then, enter the other details, i.e., “Full Name” and “Username”, and choose a password of a minimum of 8 characters. Finally, click on the “Add” button.
The user’s password will be required; enter it to confirm the creation.
Doing so will add the user “genieuser” to sudoers.
Note: All the steps are practically performed on Debian 11(the latest release of the Debian System).
The sudoers group is the group containing the users that have administrator rights. The user can be added to the sudoers group using the “chmod” command or directly adding the user to the “/etc/sudoers” file. Moreover, the Graphical User Interface of Debian can also be used to add the user to the sudoers group.