October 21, 2021
How to add user to sudoer file on Debian 11

How To Add User To Sudoers on Debian 11

On this tutorial we will show you how to add an ordinary user to sudoers group on Debian 11 operating system.

Introduction

If we have a freshly installed Debian 11 operating system, then we need a non root user who could do an administrative tasks as root user has. However, it appears that the new user does not have privileges that can run the commands owned by the root user with the sudo command. We need to add a new non root user to sudoer group. On this article, we will show you how to add user to sudoer group on Debian 11.

The sudo command stands for ‘Super User DO’ and temporarily elevates the privileges of a regular user for administrative tasks. The sudo command in CentOS provides a workaround by allowing a user to elevate their privileges for a single task temporarily. If the error message ‘ is not in the sudoers file. This incident will be reported.‘ raised when a user use command sudo on Centos, it’s meant if we have to add the user to be having sudoer privilege.

Adding User to Sudoer Group

There are at least two ways to add a user to sudoer, namely: using command line and adding the user in the file. On this article, we are assuming that the user you want to assign to the group has already exist.

1. Using Command Line

On this method, we will use the usermod -aG sudo <user>, then we will examine if the user has the sudo privilge by typing command line sudo whami.

root@otodiginet:~# usermod -aG sudo ramansah
ramansah@otodiginet:~$ sudo whoami
[sudo] password for ramansah:
root
 usermod -aG sudo
usermod -aG sudo

As shown above, the user ramansah has sudo access.

2. Adding User to the sudoers File

The /etc/sudoers is a file which is used to define the users’ and groups’ sudo privileges. We have to always use the visudo command to edit the /etc/sudoers file. The visudo command line will check the file for syntax errors when we save it. If there are any errors, the file is not saved. If we edit the file with a regular text editor, a syntax error may result in losing the sudo access. For using this command, we just type the visudo.

root@otodiginet:~# visudo

We will add the username in the file as follow :

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d
ramansah ALL=(ALL:ALL) ALL

The we will save and exit the file.

Conclusion

On this article, we have shown how to grant sudo privilege to an ordinary user on Debian 11.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *