Sudo stands for superuser do. Sudo is a command used in Unix-like systems to allow a regular user to execute a program as another user. In most cases, it is the root user.

This option gives you administrator-level permissions to run programs on your machine. It is an alternative to using the su command. However, bear in mind there are significant differences between sudo and su.

This guide will show you how to create a user with sudo privileges, add a user to a sudo group, and verify access on Debian.

Header for Add User to Sudoers Debian

Linux Sudo Command tutorials also available for:

Creating a Debian Sudo User

Creating a Debian sudo user involves a few simple steps. This procedure does not require you to edit the sudoers file. If you have an existing user that you want to grant sudo privileges, skip STEP 2.

STEP 1: Log in as the root user

Before you can add a user to your system, log in as the root user:

ssh root@ip_address

Replace ip_address with the IP address of your server.

STEP 2: Add a new user in Debian

As a root user, create a new user with the adduser command. Append the desired user account name to the command:

adduser username

For example, we added a new account sudo_user.

The output looks like this:

output after adduser sudo user command in debian

The sudo command creates a home directory for the user and copies the necessary files.

To complete the process, enter the password for the user account and retype to confirm it.

entering the password for unix

Remember that setting a strong password is extremely important for accounts with sudo access.

The terminal also prompts you to change the user information. Fill in the details or hit Enter to leave the fields blank.

changing the user information for the sudo user

STEP 3: Add user to the sudo group

Users with root privileges can add any account to the sudo group. On Debian and Ubuntu systems, everyone in this group automatically gets sudo access.

Run the following command to add a user to the sudo group:

usermod -aG sudo username

The command consists of the following parts:

  • usermod is the tool that modifies a user account.
  • -aG is the option that tells the command to add the user to a specific group. The -a option adds a user to the group without removing it from current groups. The -G option states the group where to add the user. In this case, these two options always go together.
  • sudo is the group we append to the above options. In this case, it is sudo, but it can be any other group.
  • username is the name of the user account you want to add to the sudo group.

To verify the new Debian sudo user was added to the group, run the command:

getent group sudo

The output lists all users in the group.

output checking is user was added to sudo group

Verify Sudo Access in Debian

To make sure the new user has sudo privileges:

1. Switch to the user account you just created:

su - username

2. Run any command that requires superuser access. For example, sudo whoami should tell you that you are the root.

Using Sudo

To run a command with root access, type in sudo and enter the desired command.

For example, to view details for the root directory, run the ls tool as:

sudo ls -la /root

Enter the user’s password, and the terminal shows the contents of the root directory. You only need to enter the password once in the same session.


Now you know how to add a user with sudo privileges on Debian.

By following this guide, you can use the new account to run commands as a superuser. Remember to be careful when you execute sudo commands.