In this article, we’ll show how to add user to sudoers in Debian 11. You have two ways to grant sudo privileges to a user. sudo is a command-line program that allows trusted users to execute commands as root or another user. The first one is to add the user to the sudoers file. The second option is to add the user to the sudo group specified in the sudoers file. By default, on Debian members of the “sudo” group are granted sudo access.
What you’ll learn
- How to add user in sudo group
- How to add user in sudoers file
What you’ll need
- Debian Desktop
- Root or Sudo-privileged user account
- Basic Linux command line knowledge
Adding User to the sudo Group
The best way to grant sudo privileges to a user is add the user account in the sudo group. Members of sudo group can execute any commands in the Debian as root can.
$ sudo usermod -aG sudo username
To verify that the user has been added to the sudo group, type the following \:
sudo whoami
You will be asked to enter the password. If the user has sudo access, the command will print “root”. Otherwise, you will get an error saying “username is not in the sudoers file”.
Adding User to the sudoers File
The ‘users’ and groups’ sudo privileges are defined in the /etc/sudoers file. This file allows you to grant customized access to the commands and set custom security policies.
Always use the visudo command to edit the /etc/sudoers file. This command checks the file for syntax errors when you save it. If there are any errors, the file is not saved. If you edit the file with a regular text editor, a syntax error may result in losing the sudo access.
visudo uses the editor specified by the EDITOR environment variable, which is by default set to vim. If you want to edit the file with nano, change the variable by running:
$ sudo EDITOR=nano visudo
Scroll down to the end of the file and add the following line:
username ALL=(ALL) NOPASSWD: ALL
Save the file and quit the editor. Do not forget to change “username” with the username you want to grant access to.
And then verify the user, it has been added to the sudo group, type the following :
sudo whoami
You will be asked to enter the password. If the user has sudo access, the command will print “root”.
Conclusion
So this is the way how to add user to sudoers in Debian 11. To grant sudo access to a user in Debian, simply add the user to the “sudo” group.
If you have any questions, feel free to leave a comment.
Related Posts: