How to Add Users to sudoers in Debian 11

Debian is the most stable Linux distribution of all and recently they have announced Debian 11 which contains over 11,294 new Packages with a total count of 59,551 packages. But when you install Debian 11, you will not be able to do anything which involves the sudo command.

The reason behind this is by default Debian 11 won’t add your user to its sudoers group which makes it impossible for us to make any changes to the System and that can be very frustrating if you start to get this kind of error out of the box.

In this tutorial, we will guide you through how you can elevate root privileges for existing Users on Debian and add users to sudoers and how you can create users and get them to root privileges with multiple methods.

We have already published a detailed guide to add users to sudoers in Ubuntu. You can read the article and follow the same process for Debian too.

Method 1: Adding Users to Sudoers in Debian 11 Using GUI

If you are not familiar with Terminal and still want to create and add that user in sudoers, we will guide you through how you can complete this whole process by some chicks here and there.

Open your activities by clicking on the top left corner. Search for settings and you will get the most appropriate results in the first place.

search settings

Click on Users which you will find from the right bar. You will be given Current users. Click on Unlock and you will be asked for a password. Enter your password.

user unlock

A new button named “Add user” will be available to you. Click on that button.

process of adding user

Now you will be given two options: Standard and Administrator

  1. Click on Administrator
  2. Choose the Full name, and username and enter your password.
  3. Click on Add.

As you can see, we have finally Added our new user named GeniusGeeks with Administrator privileges.

adding user final

If you want to switch users from your current to newly added, you can do it by logging out. Search for Log out in activities. Hit Enter on the most accurate result.

Log out

You will be shown two users. Select your desired one and Log in with a configured password.

Method 2: Adding Users to Sudoers in Debian 11 Using Terminal

In this method, we are going to cover a common Error that you get after installing Debian for the first time and how to solve it using a single command. Also, we are going to learn how you can add users and elevate their privileges to Administrator using Terminal.

Open your terminal by searching terminal from the App menu.

searching terminal

Use the following command to proceed further:

 su 

su

Enter your root password and you will get into the root.

If you do have a user created and just want to elevate that user to Administrator privileges, you can skip this part. This is for those who want to create a new user.

 sudo adduser {Username} 

replace {Username} with your desired one. As I want to create a new user name geniusgeeks, my command will be as follows:

 sudo adduser geniusgeeks 

sudo adduser geniusgeeks

You will be asked the following after entering this command:

  1. A new password for the user
  2. To confirm that password, enter it again
  3. Enter the Full name of the user.

You will be asked to enter your Room number, work number, and home number but we are ignoring those options. If you want, you can add them too.

To use our newly created user, use the following command:

 su – {Username} 

In our case, it would be

 su – geniusgeeks 

su - geniusgeeks

Adding user to Sudoers Group

This part is especially for those who have just installed Debian and are not able to perform any command that involves sudo.

You will get the following error which says the user is not in the sudoers file. This incident will be reported.

user is not in sudoers file

Now, for adding our user to a sudoers group, you will have to use the following command:

 su 

su for geniusgeeks

Enter your root password. Now you are working as root. Use the following command:

 sudo usermod -aG sudo {Username} 

In our scenario, the command will be:

 sudo usermod -aG sudo geniusgeeks 

sudo usermod -aG sudo {Username}

Reboot your system to apply the changes we made.

Let’s check by installing vim to our system. As you can see it involves sudo apt install vim, it has started downloading vim. So we have successfully added geniusgeeks with Administrator privileges.

sudo apt installl vim

Adding User to Sudoers by Configuring Sudoers file

If you want to make some advanced changes with the previously added user such as not asking password for logging in and performing any task using sudo without any password, this is method is perfect for you.

Open your Terminal and use the following commands:

 sudo EDITOR=nano visudo 

sudo EDITOR=nano visudo

As we are going to use nano as a text editor; write these commands in our configuration file.

{Username} ALL=(ALL:ALL) ALL

In our scenario, the command would be:

geniusgeeks ALL=(ALL:ALL) ALL

geniusgeeks ALL=(ALL_ALL) ALL

Now, you have sudo privileges for your user. To Configure our user for not asking for passwords anymore, use the following lines of code in the configuration file

{Username} ALL=(ALL) NOPASSWD:ALL

In our case, it would be:

geniusgeeks ALL=(ALL) NOPASSWD:ALL

nopassword for genius geeks in nano

As I was going to download python3, it didn’t ask me for a password. It means things are working well as we configured them.

no passwords anymore

Conclusion:

Creating a new user on Debian and adding users to sudoers for elevating its privileges to the administrator is an easy but very important process because it allows you to use sudo. Many tasks that we perform on daily basis heavily rely on privileges that we have.

Default image
Sagar Sharma

Sagar always uses Linux to its core and loves to write the technical side of system administration! While he's not writing, you can always find him exploring new Linux distros!

Articles: 31