Debian: Add user to Sudoers file [Guide]

Are you a Debian Linux user? Can’t use the Sudo command and don’t know why? We can help! Follow along with this guide as we show you how to add users to the sudoers file in Debian!

debian add user to sudoers file guide Debian: Add user to Sudoers file [Guide]

Before we begin

This tutorial will be walking you through how to add users to the Sudoers file on Debian Linux. Unlike many other Linux operating systems, Debian does not set up Sudo for the user during the installation.

However, if you are using an operating system based on Debian, such as Bunsen Labs, Devuan, SolydXK, or others, you may also not have Sudo set up. If this is the case, please follow this guide as the instructions should be similar, as these operating systems are based on Debian.

Debian add user to sudoers – adding a single user  

The easiest way to gain Sudo access for a user on Debian is to completely ignore adding users to the Sudoers file via the group management tools and instead manually editing the Sudoer file, specifying a particular user and giving them full permissions.

To start adding a single user to the Sudoers file on Debian, open up a terminal window. Once the terminal window is open, you will need to log into the Root account. The reason? The root account is required to modify system files, including sudoers.

Once your terminal window is open, you can access the root account on Debian by executing the su command in a terminal. Keep in mind you will need to remember the root password set during the Debian installation process.

su -

After logging into the root account in the terminal on your Debian PC, you’ll need to open up the Sudoers file for editing purposes. The Sudoers file is located in the /etc/ directory (/etc/sudoers). However, you should never edit the file directly. Instead, you must use the visudo command.

Note: in this guide, we’re using the Nano editor as it is approachable and easy to use for most Linux users. If you do not like Nano, feel free to change “nano” in the command below to something else.

EDITOR=nano visudo

Once the visudo command has been executed, the Nano editor will open up the Sudoers file on your Debian Linux PC. From here, use the Down Arrow key to locate the specific line “## User privilege specification“.

Under that line, you should see “root ALL=(ALL) ALL.” This code tells Debian that the Root account can use Sudo. You’ll need to replicate this line for your own user to give it Sudoer privileges. 

In the Nano editor, underneath “root ALL=(ALL) ALL” create a new line, and write in the line below. Keep in mind you will need to change “user” to your username to access Sudo in Debian.

debian add user to sudoers file guide Debian: Add user to Sudoers file [Guide]

user ALL=(ALL) ALL

Once you’ve written out the Nano text editor’s line, the Sudoers file must be saved. To save it in Nano, press the Ctrl + O button combination on the keyboard. Press Ctrl + X to exit.

Debian add user to sudoers – adding via sudo group

On Debian, if you don’t want to add users individually, the operating system also allows users to give any user account Sudo access simply by adding them to the sudo group. Here’s how to do it.

First, open up a terminal window if you don’t have one open already. On Debian, the easiest way to launch the terminal window is by pressing Ctrl + Alt + T on the keyboard. Once the terminal window is open, you must log in to the root account using the su command.

su -

Now that the terminal session is logged into the root account, you’ll need to run the grep command to determine if the “sudo” group exists on your Debian Linux PC. 

debian add user to sudoers file guide 1 Debian: Add user to Sudoers file [Guide]

grep -i "sudo" /etc/group

The output should show “sudo” and denote that your Debian Linux PC indeed has the sudo group. If for some reason, your Debian Linux system doesn’t have the sudo group as it should, you can create it using the following command in a terminal window.

groupadd sudo

After creating the new group, re-run the grep command to confirm it’s there.

grep -i "sudo" /etc/group

When you’ve confirmed that the sudo group is there, you can use the usermod -aG command to add existing users to the group. By adding users to this group, they’ll be able to execute sudo commands on Debian.

Note: be sure to re-run the usermod command below as many times as needed to give users access to sudo.

debian add user to sudoers file guide 2 Debian: Add user to Sudoers file [Guide]

usermod -aG sudo YOUR_USERNAME

Need to remove a user from the sudo group to deny them sudo privileges? You can remove any user from the sudo group by executing the usermod -G command below in a terminal window.

su usermod -G sudo YOUR_USERNAME

After removing the user from the group, they will no longer have the ability to execute sudo commands in Debian. 

Check Also

how to remove a remove apt repository from debian How to assiduousness Grippe A bacterium hinny H5N1 runway accomplished fund rationale Debian

How to assiduousness Grippe A bacterium hinny H5N1 runway accomplished fund rationale Debian

Do yous enfilade an Masterly garner on your Debian Linux PC thereupon lacrymose predicament overlay …

Leave a Reply