In Linux, sudo (super user do) is the command prefixed with any command to have the administrative rights temporarily (as an alternative to root). Whenever you want to access any system related settings or to update a system, edit the system files, you must log in as a “root” user in Linux to do so. Root users have the rights to perform any task in the system; however, sudo privileges can also be assigned to other users to act as a root.

It is recommended to use sudo command carefully, as it has all admin rights so any misuse of this command may lead to several system’s problems. Debian is a well-known Linux distro and the latest release of this distro is Debian 11. The sudo user’s information resides in sudoers file, this file is in directory “/etc/sudoers”; the users included in sudoers file can perform all the tasks that a root can do.

In this article, we will demonstrate the possible ways to add any user to sudoers file to assign sudo privileges to that user.


We have listed down the possible ways to add users to sudoers in Debian 11:

Method 1: How to add user to sudoers using terminal in Debian 11

Method 2: How to add user to sudoers using GUI in Debian 11

Let’s dig into these methods one by one:

Method 1: How to add user to sudoers using terminal in Debian 11

Open the terminal in Debian 11 by clicking on “Activities” and then search for terminal as shown in the image below:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-1.png" data-lazy- height="265" src="data:image/svg xml,” width=”744″>

Once the terminal is opened, you have to add the user first by issuing the following command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-2.png" data-lazy- height="327" src="data:image/svg xml,” width=”673″>

You can switch to this user by using the switch user command as written below: it will ask you to enter the password for “user1” and the user will be switched:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-3.png" data-lazy- height="56" src="data:image/svg xml,” width=”593″>

Now if you execute the sudo command as a “user1”; the command will not be executed because the user1 does not exist in sudoers file:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-4.png" data-lazy- height="76" src="data:image/svg xml,” width=”689″>

As it is clear that “user1” does not exist in sudoers file, in this case, you can use usermod command with various flags to add any user to grant sudo privileges. Here we will use two flags in usermod command; “-a” flag of usermod helps to append the user to a specific group; and “-G” flag is applied to indicate the group name to which the new user will be added mentioned below to add user “user1” to sudoers file: For instance, the following command will help you to add “user1” to sudo group.

Now you can see that after switching to “user1”; the “sudo apt update” command ran successfully:

$ sudo usermod -a -G sudo user1

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-5.png" data-lazy- height="273" src="data:image/svg xml,” width=”748″>

Method 2: How to add user to sudoers using GUI in Debian 11

In this method, graphical interface of Debian 11 will be used to add a new user with sudo privileges; so for this you have to follow few steps:

Open the settings by navigating to “Activities” and then search for settings:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-6.png" data-lazy- height="266" src="data:image/svg xml,” width=”876″>

Open the settings, scroll down the left side pan and choose “Users” here, you will see the existing users on the right-side pan, before adding user you have to click on “Unlock” to make changes:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-7.png" data-lazy- height="425" src="data:image/svg xml,” width=”953″>

After clicking “Unlock”; it will ask you to enter the user password, type your password and click on “Authenticate”:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-8.png" data-lazy- height="452" src="data:image/svg xml,” width=”583″>

After authentication, click on “Add User” button:

Note: This button will only be visible if you have unlocked the users pan:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-9.png" data-lazy- height="285" src="data:image/svg xml,” width=”955″>

After clicking on “Add User”; a new window will be displayed in which you have to do the following changes:

  • Firstly, set the “Account Type” to “Administrator”:
  • Enter Full Name and Username; we have used “LinuxHint” as full name of new user and “user2” for username:
  • Next opt for “Set Password now” and enter password for “user2”:

Once you have performed these changes, click on “Add” button to add “user2”:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-10.png" data-lazy- height="647" src="data:image/svg xml,” width=”608″>

Authenticate the addition of new user by entering the password:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-11.png" data-lazy- height="430" src="data:image/svg xml,” width=”458″>

Once the authentication is successful you can check the new user “LinuxHint” has administrator privileges that mean it can perform sudo tasks now:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-add-users-to-sudoers-12.png" data-lazy- height="550" src="data:image/svg xml,” width=”631″>

Conclusion

In computing devices, there are multiple users that might be using a single device; it is observed that only few users can perform maximum tasks. In Linux, a root user has the access to work on the system without any restriction, whereas sudo users also have the same access but for a limited time. In this descriptive post, we have demonstrated the ways to add new users and add them to sudoers; for this we have primarily mentioned two methods. The first method is for terminal enthusiasts and the second method refers to graphical support of adding users to sudoers. You can adopt any of the methods to do so, but terminal quickly does the process.