How to Add a New User to Sudoers on Debian 12, 11 or 10

Managing administrative privileges is crucial when working with Debian systems. This guide will detail how to add a new user to sudoers on Debian 12 Bookworm or the older stable releases of Debian 11 Bullseye or Debian 10 Buster. By doing so, you grant them the capability to execute commands with superuser rights.

Why Create Sudoers on Debian?:

  • Enhanced Security: Instead of operating as the root user, which can be risky, sudo allows specific users to execute certain commands with elevated privileges, reducing potential system vulnerabilities.
  • Flexibility: Granting sudo access ensures multiple users can perform administrative tasks without compromising the root account.
  • Audit Trail: Using sudo can provide a clear record of which user performed which command, aiding in system monitoring and troubleshooting.
  • User Restrictions: Sudoers can be configured to allow specific users to execute only certain commands, offering granular control over user permissions.

With these benefits in mind, we’ll now delve into the step-by-step process of enhancing user permissions on your Debian system.

Step 1: Change to Root Account on Debian

To add a new user with sudo privileges on Debian, first switch to the root account. You created this account and set its password during Debian’s installation.

Use the command:

su

After verifying the root password correctly, the username will show as “root”, showing you’ve switched to the root user.

Output example:

root@debian:/home/joshua# 

Install the sudo package on Debian (Situational)

If the sudoers file is missing or removed, reinstall the package with this command:

sudo apt install sudo

Step 2: Create a New User Account on Debian

To establish a new user, we utilize the adduser command, accompanied by your desired username. For instance:

sudo adduser <example username>

For instance, to add a user named “josh”:

sudo adduser josh

Once you run this command, Debian initiates the user creation process. Immediately, you’re asked to specify a password. Given the critical nature of passwords in safeguarding accounts, opting for a resilient password is pivotal. Aim for a mix of uppercase letters, lowercase letters, numbers, and symbols. The password serves as the first line of defense against unauthorized access, more so for users with sudo privileges.

Screenshot showing setting a new password for a new user account on Debian.
Secure your new user by setting a strong password—screenshot from Debian Linux.

Providing Supplementary User Information

After defining a password, Debian seeks additional details about the user—like their full name or contact data. Though not mandatory, supplying this data can benefit systems with multiple users, ensuring clarity on user identities. If you’d instead not share extra information, hit the enter key, and the system will progress to the subsequent prompt.

Screenshot displaying a new user's details correctly added on Debian.
Confirmation screenshot of a new user added with all the correct details on Debian Linux.

On completion, confirm your details by pressing “Y” and then enter.

Verifying the User’s Addition

Post creation, verifying that Debian has indeed recorded the new user is prudent. A straightforward method involves the cat command, targeting the /etc/passwd file:

cat /etc/passwd

This command retrieves a list of all system users. Spotting the freshly created user in this list signifies a successful addition.

Screenshot showing a list of users and confirmation of user status using password check and cat command on Debian Linux.
Using commands to list and verify user status on Debian Linux. An essential step for system administrators.

The /etc/passwd file, a fundamental part of Debian’s structure, catalogues key data about users, encompassing their username, user ID, group ID, home directory, and chosen shell. As a system administrator or a user, understanding the significance of this file can aid in tasks ranging from user authentication to intricate system management. Regularly revisiting and maintaining this file ensures the system’s smooth functionality.

Step 3: Add a New User To the Sudoers Group on Debian

In the next section, having learned how to add a user to the system, you will now learn how to grant the newly added or existing user sudo privileges.

To do this, execute the following command:

sudo usermod -aG sudo <example username>

For illustration purposes, if you’re looking to grant rights to a user named “josh”, you’d key in:

sudo usermod -aG sudo josh

Ensuring that the user has indeed been incorporated into the sudoers group is paramount. You can ascertain this by employing the id command:

id <username>

By replacing <username> with the specific user’s name, the command furnishes details about the user, encapsulating their user ID, group ID, and any additional group affiliations. Notably, if “sudo” appears in the group list, the user is endowed with sudo rights.

For instance, running the command for the user “josh” would appear as follows:

id josh

The anticipated output would be:

uid=1001(josh) gid=1001(josh) groups=1001(josh),27(sudo)

An alternate avenue to grant sudo rights is by deploying the gpasswd command:

gpasswd -a <example username> sudo

Substitute <username> with the desired user’s name. This command integrates users into the sudo group, bestowing them sudo privileges.

For example:

gpasswd -a joshua sudo

The resulting output should be:

adding joshua to group sudo

Step 4: Confirm New Sudo User on Debian

Upon successfully granting sudo privileges, it’s wise to gauge the user’s capabilities. This can be achieved using the su command:

su <example username>

Replace <username> with the name of the user you have accorded sudo access. This action transitions you to the user’s account, enabling you to verify their sudo capabilities.

To illustrate:

su josh

Verify the username by executing the following command: “sudo whoami.”

sudo whoami

After you input the correct sudo user credentials, a confirmation will greet you, highlighting the user’s ability to manage administrative tasks on Debian.

The expected output is:

root

Congratulations, you have successfully added a new user to the sudoers group and granted them elevated privileges on Debian.

Conclusion

To conclude, when you want to add a new user to the sudoers group on Debian, you create the user account, set their password, and grant them sudo access. This process requires you to log into the Debian root account, create the user account, choose a password, add the user to the sudoers group, and verify their sudo access. You can accomplish this with the usermod or gpasswd commands and then test the new user account using the sudo command. By following these steps, you equip a new user with the necessary permissions to run commands with elevated privileges on Debian.

Leave a Comment


Your Mastodon Instance
Share to...