If you are worried about the superuser (root) privileges. No need to worry by adding user to sudoers in Debian 12“. We are here to fix it!
It is basically a important task for granting administrative privileges. It allows a user to execute commands with superuser (root) privileges, which is essential for system administration tasks.
How to Add a User to Sudoers in Debian 12
To add a user to sudoers in Debian 12, follow below steps:
Step 1: Switch to the Root User
First of all, you need to modify the sudoers file. For this, switch to the root user by typing the below command:
su -
Note: Enter the root password when prompted. If you don’t have the root password, you can use a user with sudo privileges to execute the above command with sudo.
Step 2: Open the Sudoers File
The sudoers file is located at /etc/sudoers. It’s crucial to edit this file using the visudo command to prevent syntax errors.
Let’s open the sudoers file by executing the below command:
visudo
Step 3: Add the User to the Sudoers File in Debian 12
After that, move downward to the section that looks like:
# User privilege specification
root ALL=(ALL:ALL) ALL
Finally, add the following line, replacing sharqa with the actual username:
sharqa ALL=(ALL:ALL) ALL
Note: This line permits the specified user full sudo privileges.
Step 4: Save and Exit
Now, save the file by pressing Ctrl + O, then press Enter. After that, exit it by hitting Ctrl + X.
Step 5: Verify the Added User to Sudoers File
To ensure that the user has been added to the sudoers file correctly, switch to the user and run a command with sudo as below:
su - sharqa
sudo whoami
Alternative Method: Using Usermod Command
Another way to add a user to the sudoers file is by adding them to the sudo group. This method is simpler and doesn’t require editing the sudoers file directly.
For this, add the user to the sudo group:
sudo usermod -aG sudo sharqa
Finally, verify the changes:
su - sharqa
sudo whoami
This is all about adding the user to the sudoers file on Debian system.
Conclusion
To add a user to the sudoers file in Debian 12, open the terminal and run sudo usermod -aG sudo <username>. This command grants the specified user administrative privileges, allowing them to execute commands with superuser rights.