Debian

How to Enable “sudo” on a User Account on Debian

In Debian, the sudo command is only enabled for the root user by default. Thus, you won’t be able to execute any command on the terminal even if you are the only user on the system. To run the sudo commands on Debian as a system user, you must enable the sudo access on your current user account so that you will be able to run commands like updating the system, installing an application and more.

This article is a guide to enabling “sudo” on a user account on Debian.

How to Enable “sudo” on a User Account on Debian?

While running a sudo command on the Debian terminal, you may experience the following error like “user is not in the sudoers file”:


To fix the error, you must enable the sudo on your current user account, which is “myuser” in my case. To add myuser to a sudoers file, there are two methods which are mentioned below:

Method 1:  By Using “adduser” Command

In Linux based system, the adduser command is used to add a user to any specified group, the syntax for adduser command is given below:

Note: Remember that to adduser to any group, first switch the user to root user by using “su root” command:

After that, you can execute the following command syntax:

Syntax

sudo adduser <username> <group>

 
In the above-written command replace <group> with “sudo” to enable sudo on a user account:

For example;

sudo adduser myuser sudo

 

You can also directly add the user to the root group if you want to assign all the root privileges too:

sudo adduser myuser root

 

Verification

To verify that the desired user has been successfully added to sudo group, switch to that user and run the below-written update command:

sudo apt update

 
In the output, you can see that this command is now running successfully which ensures that the sudo is successfully enabled on a user account on Debian:

Method 2: By Editing “sudoers” File

The other method to enable sudo on a user account is by editing the sudoers file. In all Linux-based systems, sudoers file is the file which contains the information of all the sudo enabled users.

To edit the sudoers file, open it by using any nano editor:

sudo nano /etc/sudoers

 
Then find the below-mentioned text inside the file:

root    ALL=(ALL:ALL) ALL

 

And under the above-mentioned text add a new line with your desired username:

<username>  ALL=(ALL) NOPASSWD:ALL

 
For example:

myuser  ALL=(ALL) NOPASSWD:ALL

 

After editing save the modified sudoers file by using the shortcut keys Ctrl+X, then Y and finally press Enter to get back to the terminal.

Verification

To verify that the user has been successfully added to the sudo group, run the below-written update command after switching to the targeted user:

sudo apt update

 
The update command should now run successfully as shown in the image below:

Conclusion

In the Debian system none of the users are sudo enabled by default and to enable the sudo privileges for a desired user, one should add that user to the sudo group. There are two ways to enable sudo on a user account one is by using the “adduser” command and the other is by manually editing the sudoers file to assign the sudo privileges to a desired user.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.