Add User to sudoers File on Debian

This article shows how to add a user to the sudoers file on Debian Linux. This will allow a normal user to run commands with elevated privileges by prefacing a command with sudo. Without going through these steps, it’s common to receive the error message below.

linuxnightly is not in the sudoers file.  This incident will be reported.

The sudoers file can be found at /etc/sudoers, but it’s not recommended to edit this file directly. Instead, follow the steps below to grant a user sudo privileges.

Give User sudo Access on Debian

1. To give a user sudo privileges, we need to add that user to the system’s sudo group. To get started, open a terminal and login with your root account.

$ su

2. Next, add the user to the sudo group with the usermod command. As an example, we’ll add a user named linuxnightly.

# sudo usermod -aG sudo linuxnightly

3. For the new changes to take effect, you’ll need to reboot the system.

# sudo reboot

4. When you boot back into Debian, you can run the groups command to see that your user has been added to the sudo group. To further verify, try running a simple command that normally requires root permission, like apt update.

$ groups
$ sudo apt update

Testing out sudo access for a normal user account on Debian

Create a New User With sudo Access

When creating new users on Debian, you can give them instant sudo access at the time of creation by adding them to the sudo group. For example, this command creates a new user named linuxnightly and adds them to the sudo group.

$ sudo useradd -G sudo linuxnightly

If our content helped you, please consider buying us a coffee. We appreciate your support!

Buy me a coffee donation button

Leave a Comment

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