How to

How To Add a User to Sudoers On Debian

Add a User to Sudoers

Unlike many other Linux operating systems, Debian does not really set up Sudo for the user during the installation. But, if you guys are using an operating system based on Debian. Such as Bunsen Labs, Devuan, SolydXK, or any others, then you may also not have Sudo set up. If this is the case, please follow this guide as the instructions should be similar, just like these operating systems are based on Debian. In this article, we are going to talk about How To Add a User to Sudoers On Debian. let’s begin!

How To Add a User to Sudoers On Debian

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

In order to start adding a single user to the Sudoers file on Debian, just open up a terminal window. When the terminal window is open, you will have to log into the Root account. The reason? The root account is required to modify system files, also including sudoers.

When your terminal window is open, you can also access the root account on Debian via executing the su command in a terminal. Just keep in mind you will need to remember the root password set during the Debian installation process as well.

su -

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

Further

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

EDITOR=nano visudo

When the visudo command has been executed, the Nano editor will then open up the Sudoers file on your Debian Linux PC. From here, you can use the Down Arrow key in order to locate the particular line “## User privilege specification“.

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

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

When you’ve written out the Nano text editor’s line, the Sudoers file must be saved. In order to save it in Nano, tap on the Ctrl + O button combination on the keyboard. Click on Ctrl + X to exit.

Debian add a user to sudoers – adding via sudo group

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

First of all, open up a terminal window if you guys don’t have one open already. On Debian, the easiest way to open the terminal window is via pressing Ctrl + Alt + T on the keyboard. When the terminal window is open, then you must log in to the root account via the su command.

su -

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

grep -i "sudo" /etc/group

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

groupadd sudo

Further

After you create the new group, re-run the grep command in order to confirm it’s there.

grep -i "sudo" /etc/group

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

Note: make sure to re-run the usermod command below a lot of times as needed to give users access to sudo.

usermod -aG sudo YOUR_USERNAME

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

su

usermod -G sudo YOUR_USERNAME

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

Alright, That was all Folks! I hope you guys like this article and also find it helpful to you. Give us your feedback on it. Also if you guys have further queries and issues related to this article. Then let us know in the comments section below. We will get back to you shortly.

Have a Great Day!

Also See: How to Watch Venom on Netflix – Is it Available

About the author

Windy Moore

Leave a Reply