Managing user privileges is an important aspect of maintaining proper security in a Debian system. Debian is widely recognized for its stability and reliability, and it provides system administrators the ability to manage user privileges effectively.
To exercise administrative privileges on a Debian system, you need to be on the sudoers list. If you are a root user, you can add any users you want to the sudoers list. There are two options for adding users to the Debian sudoers list: using the visudo command or manually editing the sudoers file.
In this blog post, I will show you how to effectively add users to the sudoers file.
Prerequisites
Before adding a new user to Debian, you must meet the following requirements:
- You are a superuser or have root permissions.
- You have administrative privileges.
- You have text editors like Nano or Vim
Switching to the Root User
Before proceeding with adding a user to sudoers in Debian, you need to switch to the root user. To do this, simply enter the following command in your terminal:
su -l
This command will change your current user account to the root account.
Adding a User to the Sudoers List
If you want to grant administrative access to any users, you need to add the user to the sudoers list. There are two methods for adding a user to the sudoers list in Debian: using the visudo command or manually editing the sudoers file.
Method 1: Using the visudo Command
The visudo command provides an easy way to add users to the sudoers list in Debian. The visudo command requires root account access to work, which is why we switched to the root account in the previous step.
To add users to the sudoers list, first open the terminal on your Debian system and enter the following command:
visudo
In the sudoers file, locate the following line:
# User privilege specification
root ALL=(ALL:ALL) ALL
Then, add the line with sudoers specification below the root ALL=(ALL:ALL) ALL
line in the sudoers file:
# User privilege specification
root ALL=(ALL:ALL) ALL
#Replace username with the specific user’s name you want to add.
username ALL=(ALL) ALL
Afterward, save the file by pressing Ctrl + O
and exit the editor by pressing Ctrl + X
.
Verifying the Changes
To verify that the new user has been successfully added, you can run a command with sudo. Before running commands as a sudoer user, switch to your user account using the following command:
su username
Once you have switched to the user account, run a command with sudo to verify that the user account is listed as a sudoer. For example, you can run the following command:
sudo apt update
Method 2: Modifying the sudoers File Manually
If you encounter any problems while running the visudo command, you can try manually editing the sudoers file using a text editor like Nano or Vim. The sudoers file in Debian is located at /etc/sudoers
. You can open the file with root account access to edit it manually.
First, switch the user account to the root account in Debian by running the following command:
su -l
Then open the /etc/sudoers
file
in your favorite text editor. For example, you can edit the sudoers file using Nano:
nano /etc/sudoers
Locate the root ALL=(ALL:ALL) ALL
line in the sudoers file and add a new line below it to add users to the sudoers in Debian:
# User privilege specification
root ALL=(ALL:ALL) ALL
#Replace username with the specific user’s name you want to add.
username ALL=(ALL) ALL
After adding users to the sudoers list, it is recommended to verify that the users have been successfully added by running some sudo commands with the user account. For example, you can run the following command:
sudo apt update
Conclusion
In this blog post, I’ve covered two methods for adding a user to the sudoers list in Debian. Sudoer users are granted the ability to run any administrative command in the Debian system, making them essential for maintaining the system’s integrity.