If you’re managing a Debian-based Linux system, you may need to grant certain users the ability to run administrative commands with elevated privileges. In Debian, this is typically done by adding the user to the sudo group, which allows them to use the sudo command to perform administrative tasks. In this post, we’ll walk through the steps required to add a user to sudo on Debian.

Step 1: Log in as root

To add a user to the sudo group, you’ll need to have root-level access to the system. Log in as the root user or switch to the root account using the “su” command.

Step 2: Create a new user (optional)

If you haven’t already created a user account for the person you want to grant sudo privileges to, you can do so now using the “adduser” command. For example, to create a new user named “johndoe”, run the following command:

adduser johndoe

Step 3: Add the user to the sudo group

To add the user to the sudo group, use the “usermod” command. The “-aG” option is used to add the user to a secondary group (in this case, the “sudo” group). For example, to add the user “johndoe” to the sudo group, run the following command:

usermod -aG sudo johndoe

Step 4: Test sudo access

Once you’ve added the user to the sudo group, you can test their sudo access by logging in as that user and running a command that requires elevated privileges. For example, you can run the following command to update the system’s package lists:

sudo apt update

If the command runs successfully without prompting for a password, then the user has been granted sudo privileges.

Step 5: Optional – Require a password for sudo

By default, Debian does not require a password for users in the sudo group when they run administrative commands. However, you can change this behavior by editing the sudoers configuration file.

To require a password for sudo, run the following command to open the sudoers file in the nano text editor:

sudo nano /etc/sudoers.d/myOverrides

Then, add the following line to the file:

%sudo ALL=(ALL) PASSWD: ALL

This tells the system to require a password for all members of the “sudo” group when they run administrative commands. Save the file and exit the editor.

Conclusion

Adding a user to the sudo group on Debian is a straightforward process. By following the steps outlined in this post, you can grant users the ability to perform administrative tasks without having to give them full root access to the system.