How To Add Users in Sudoers File in Debian 12

Managing user permissions through the sudoers file is a powerful way to control who can execute commands as the superuser. In Debian 12, adding users to the sudoers file is a crucial task for system administrators who want to grant certain users the ability to perform tasks with superuser privileges.

By considering its importance, this article will guide you through the various methods available for adding users to the sudoers file, ensuring that you can manage your system’s security and user permissions effectively.

Table of Content

How To Add Users in Sudoers File in Debian 12

Method 1: Using the usermod Command

Method 2: Using the visudo Command

Method 3: Using the useradd Command

Method 4: Directly Editing the sudoers File

Method 5: Using the GUI

Conclusion

How To Add Users in Sudoers File in Debian 12

On Debian 12, adding users to the sudoers file allows them to run commands with root privileges. Debian 12 offers multiple methods to accomplish this task whether you prefer the command line or the graphical interface:

Method 1: Using the usermod Command

The usermod command is a straightforward way to add the user to the sudo existing group, which inherently grants them sudo permission. Here’s how you can do it:

Add the user to the sudo group

Use the below command to add the user to the sudo group. For instance, the username in our case is debian (existing user):

Add the user to the sudo group

Verification

You can use the groups command to verify whether the user has been added or not to the sudo group:

Add the user to the sudo group

Method 2: Using the visudo Command

This command is an easy and safe way to edit the sudoers file. It launches the sudoers file in the editor and checks for errors before saving.

Add Users in Sudoers File

To launch the sudoers file, enter the visudo command:

Locate the root entry by scrolling down to find the line that starts with the root. This is the entry for the root user:

Using the visudo Command

Below the root entry, add a new line with the following format:

Here, <username> is the username that the user wants to add. <group> can be either ALL to allow all commands or a specific group name. <command> specifies the commands the user can execute with sudo. If you want to allow all commands, leave it blank.

Using the visudo Command

Finally, save and exit the editor.

Method 3: Using the useradd Command

For the addition of users in the sudoers file on Debian 12, use the useradd command below:

Create a New User

If users need to add the user and grant sudo permission, use the useradd command to create the new user account:

Users need to replace <username> with the desired username as John:

Using the useradd Command

Set the user’s password

After that, utilize the passwd command to set the password for the new user as John:

Using the useradd Command

Grant sudo privileges

Use the visudo command as described in Method 2 to add the new user to the sudoers file.

Method 4: Directly Editing the sudoers File

For the addition of users in the sudoers file in Debian 12, use the sudoers file. It is one of the recommended methods to directly edit the sudoers file:

Open the sudoers file

Open a terminal and utilize the preferred text editor (such as nano) to open the sudoers file:

 Directly Editing the sudoers File

Now, add the below line to the file and replace <username>:

 Directly Editing the sudoers File

After modification, save and exit the editor.

Method 5: Using the GUI

For those who prefer a graphical interface, Debian provides a GUI method to add users to the sudoers file:

Add Users in Settings

Open the system settings, and navigate to the “Users” section. If you hit the “Unlock” button authenticate if required. Finally, select “Add User” and fill in the new user credentials:

Using the GUI

Toggle the button to “Administrator” to grant sudo privileges:

Using the GUI

Verification

To confirm the successfully adding user in the Sudoers file in Debian 12, see the below interface:

Using the GUI

That is all from the guide.

Conclusion

To add a user to the sudoers file in Debian 12, you can use the usermod command. For example, sudo usermod -aG sudo [username] will grant [username] sudo privileges. Alternatively, you can use the visudo command to edit the sudoers file directly and add [username] ALL=(ALL:ALL) ALL to grant the necessary permissions. It’s important to replace [username] with the actual username of the user you wish to add. For a GUI approach, navigate to the Users settings in Debian and toggle the Administrator option for the new user.

Scroll to Top