How to Create a Sudo User on Debian

April 22, 2019


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 <em>username</em>

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 <em>username</em>

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 - <em>username</em>

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.

Was this article helpful?
Goran Jevtic
Goran combines his passions for research, writing and technology as a technical writer at phoenixNAP. Working with multiple departments and on a variety of projects, he has developed extraordinary understanding of cloud and virtualization technology trends and best practices.
Next you should read
How To Install Debian 10 (Buster)
October 14, 2019

Debian has released its newest stable version Debian 10, nicknamed Buster. This article will help you how to install Debian 10 Buster as your operating system with easy to follow, step-by-step instructions.
Read more
How To Install PIP on Debian 9
April 10, 2019

Pip means "preferred installer program" or "Pip installs packages." In this tutorial, learn how to install Pip for Python 2 & 3 on Debian 9.
Read more
How to upgrade Debian 9 Stretch to Linux Debian 10 Buster
March 29, 2019

Debian 10, codenamed Buster, is still a work in progress, but a pre-release version is available. Even though Debian 10 has not reached its final release date, you can still run the upgrade.
Read more
How to Upgrade Debian 8 Jessie to Debian Linux 9 Stretch
March 24, 2019

Debian is one of the main distributions, of the Linux operating system. This guide will walk you through upgrading Debian 8 (Jessie)to the next version, Debian 9 (Stretch).
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.