How to add a user to sudo group on debian

Sudo stands for superuser do means whats superuser can do. A superuser is a root user that has full system access and can do pretty much everything on the system. Tasks like installing, updating, upgrading, deleting important files, modifying configuration files, starting and stopping system services require root powers.

As these tasks can modify the system and sometimes even harm the system they require root privileges. But we can’t make everybody a root user as it will be extremely dangerous. And Linux doesn’t even have an Undo option making another root account is risky.

So to perform everyday administrative tasks sudo comes in. For instance, when a regular user wants to perform administrative tasks they can perform using sudo command. Basically sudo lets a regular user exercise some of the superuser powers. But the condition here is that the user who wants to use sudo needs to be in the sudo group on Debian.

In this guide, we will see how to create a new user and then add that user or any other user to sudoers group on Debian.

Step 1: Logging Into Your Server

Let’s start by logging in as a root user on Debian server via SSH

# ssh root@server_ip_address

Here replace server_ip_address with the IP address of your server. If you have created a server instance without selecting an SSH key to use for authentication. Then you will typically receive a password through email use this password to login.

Step 2: Create a new user account

To create a new user we are going to use adduser command here.

# adduser newusername

For example, here we are adding nick as the new user.

# adduser nick

This command will prompt you to enter the password for the new user’s account and then confirm it by retyping. Just remember to keep a strong password. Once the password is successfully set, the command will ask about additional information of the user. You can leave all of this information blank, just hit Enter.

New users by default, will not be able to modify files out of their home directory. For that, we need to add the new user to the sudo group.

Step 3: Add the new user to sudoers list

Now let’s add the new user to sudo group by using usermod command. Type the command as follows.

# usermod -aG sudo newusername

For instance we are adding nick to sudoers group

# usermod -aG sudo nick

Step 5: Testing the newuser with sudo

Now as we have added the new user in sudoers group lets verify if its done properly. For that switch to the new users account.

# su - newusername
# su - nick

The above command will login you into the newuser account. You can now verify sudo access through any command.

Deleting a User

Now when you are done and don’t need a user account anymore you can delete that account by the following command.

deluser --remove-home username

Here –remove-home option will also delete that user’s home directory. If you are not logged in as root then use sudo in that command.


Now you know how you can a new user and add that user to sudo group on Debian. And as a piece of advice always keep a secure password.

Would you like to know how can you mount NFS in Linux, just click here

Leave a Reply

Share via
Copy link
Powered by Social Snap