April 22, 2025
Tutorials

How to Add Users to Sudoers on Debian 12: Complete Tutorial

How to add users to sudoers on Debian 12

Controlling user permissions by using the sudoers file is quite an efficient way to limit the execution of commands with superuser privileges. For instance, in Debian 12, system administrators are expected to add users to the sudoers file in order to provide superuser privilege access to some specific users. For that reason, this article will explain the various methods that exist for adding users to the sudoers file so that you do not compromise on the matter of system security.

Table of Contents

How To Add Users to Sudoers File on Debian 12

Final Words

How to Add Users to Sudoers File on Debian 12

To grant a user root privileges on their commands on a Debian 12 machine, you need to add that user to the sudoers file in the system settings. It can be accomplished in multiple ways whether you like the command line, GUI, or even via software tools.

Method 1: Using the usermod Command

One of the simplest methods is to add a user to the sudo group using the usermod command, thereby granting permission to execute sudo commands:

Add the user to the sudo group

To do so, you may replace ‘debian 12‘ with your actual username:

  sudo usermod -aG sudo <username>
sudo usermod -aG sudo <username>

Verification

You may also check the username whose group you just modified by using the groups command as follows:

  groups <username>
  groups <username>

Method 2: Using the visudo Command

This command allows you to edit previously entered commands in sudo safely. It opens the sudoers file in the editor and then runs a check for errors before allowing a save.

Add Users in Sudoers File

Now, you can open the sudoers file by opening it with the visudo command:

  sudo visudo

Find the line that has the starting word ‘root’, and you can scroll down to find it.

  sudo visudo

Here is the entry corresponding to the root user. Under the root entry, add a new line following this format:

  <username> = <group> <command>

As previously mentioned, <username> is the user that the user wants to add. <group> can be either ALL to command all to any task, or a certain group name. <command> refers to the specific commands that can be executed with sudo. If indeed all commands are to be permitted, then leave it blank.

<username> = <group> <command>

At last, save and exit the editor.

Method 3: Using the useradd Command

To add users to the sudoers file in the Debian 12 system, utilize the useradd command mentioned below:

Creating a New User

In case other users can add the user and give them sudo permission, execute the useradd command along with the new user details:

  sudo useradd <username>

As such, the users have to change <username> with the needed username, as John:

sudo useradd <username>

Set the user’s password

Then, execute the command to set the new password for John as follows:

  sudo passwd <username>
  sudo passwd <username>

Grant sudo privileges

Thereafter, John can reset the password associated with the account hosting the Linux system using the command ‘passwd’. Afterward, use the visudo command as explained in method 2 to give permissions to reset the password associated with the account to the user described above.

Method 4: Editing the sudoers File

As in any Linux Operating System, users can be added using the Sudoers file in Debian 12. Editing the sudoers file is one of the popular methods with advanced users:

Open the sudoers file.

Enter the terminal and use your desired text editing application (like nano) to edit the sudoers file:

  sudo nano /etc/sudoers

The below line should be added to the file at the appropriate location:

  <username> ALL=(ALL:ALL) ALL
<username> ALL=(ALL:ALL) ALL

Adjustments must be made to the username placeholder within the text above. Afterwards, remember to save changes and exit the editor.

Method 5: Using the GUI

Suppose a GUI is more appealing to you. In that case, there is a Window Interface approach in Debian to eliminate users from the sudoers file, enabling the removal of both GUI and terminal using the Debian system:

Add Users in Settings

Access the system settings, and progress to the “User” tab. Click on the “Unlock” option if needed. Choose “Add User,” and input the credentials of the new user:

Adding user in sudoer using gui

As noticed before, when the button is set to “Administrator,” this implies granting sudo access:

Adding user in sudoer using gui

Verification

To verify the user has been correctly added to the Sudoers file in Debian 12, navigate to the following interface:

Adding user in sudoer using gui

That is all from the guide.

Final Words

To add a user to the sudoers file in Debian 12, you can add a user to the sudoers file by using the usermod command as follows: sudo usermod -aG sudo [username] will give [username] sudo privileges. Another option is using the visudo command to edit the sudoers file directly and adding [username] ALL=(ALL: ALL) ALL. Do not forget to replace [username] with the corresponding username of the account that you want to add. If you prefer a graphical method, you can go to Users in the settings of Debian and check the Administrator box for the new user.

Frequently Asked Questions

You can add a user to the sudoers file by running sudo visudo and adding the line username ALL=(ALL) ALL to grant them sudo privileges.
visudo is a safe editor for modifying the sudoers file, preventing syntax errors that could lock out sudo access. It checks for errors before saving.
Yes, you can add a user to the sudo group by running sudo usermod -aG sudo username. Users in this group have sudo access by default.
To check if a user has sudo privileges, run groups username and confirm if sudo is listed in the groups.
To remove a user from the sudo group, use the command sudo deluser username sudo. This removes the user’s sudo privileges.

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video