Newsletter Subscribe
Enter your email address below and subscribe to our newsletter
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.
Table of Contents
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.
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.
A new button named “Add user” will be available to you. Click on that button.
Now you will be given two options: Standard and Administrator
As you can see, we have finally Added our new user named GeniusGeeks with Administrator privileges.
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.
You will be shown two users. Select your desired one and Log in with a configured password.
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.
Use the following command to proceed further:
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
You will be asked the following after entering this command:
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
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.
Now, for adding our user to a sudoers group, you will have to use the following command:
su
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
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.
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
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
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
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.
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.