How To Create a Sudo User on Debian

In this guide, we will show you how to create a new user on a Debian system and give it sudo access.

Updated: 14 Apr, 23 by linda Y 5 Min

List of content you will read in this article:

Giving complete control over your Linux server to other users is not something many server owners wish to do. Therefore, giving root user access out is not the best way to go.

In this guide, we will show you how to create a new user on a Debian system and give it sudo access. You can use this user account to execute administrative commands without a need to log in to your Debian server as a root user.

 

As you may already know, when we mention the Linux operating system, we are talking about a collection of Linux distributions that are using the Linux kernel. Unlike Windows or macOS, there is no one owner of the operating system. Some common names of Linux distributions are: Ubuntu, CentOS, RHEL, Kali Linux, and of course, Debian.

The Debian Project is a group of programmers that strive to create a free and feature-rich operating system.

 

When making any changes to a Linux server or VPS, root user, also known as a superuser, access is required. Put simply, a root user is the administrator account on the device, with the user id 0, and has unlimited privileges. Root can access any file, run any program, execute any system call, and modify any setting. It is, however, important to know that some modern Unix versions can restrict even what the root user can do.

 

In reality, there is no such thing as a sudo user, it is a command that allows a normal user to perform certain tasks with the security privileges of another user, typically, the root user. In fact, the command itself is the abbreviation of the words “superuser do”.

When a sudo command is ran, it prompts for the user to enter their personal password as an additional security measure. Afterward, it confirms the request to execute the command by checking the sudoers file.

 

Difference between a Sudo and Root User

Before the sudo command was a thing, performing any administrative tasks required you to login using the root user. As you can imagine, having to do this is quite inconvenient and can even cause certain security issues to arise. Also this solution did not have the possibility to give users partial administrative privileges. To circumvent the hassle, the sudo command was invented.

As mentioned in the previous chapter, sudo in itself, is not a user bus simply a command that grants you the ability to execute the following string with superuser security privileges. On the other hand, the root is the default Unix superuser.

 

Follow the steps below to create a new user account and give it sudo access. If you want to configure sudo for an existing user, skip to step 3.

Step 1: First, log in to your linux server as the root user:

$ ssh root@server_ip_address

Step 2: Create a new user account. Do so using the adduser command. Don’t forget to replace username with your desired user name:

$ adduser [username]

The command will prompt you to set and confirm the new user password. Make sure that the password for the new account is as strong as possible (combination of letters, numbers and special characters).

Output

Adding user `username' ...

Adding new group `username' (1001) ...

Adding new user `username' (1001) with group `username' ...

Creating home directory `/home/username' ...

Copying files from `/etc/skel' ...

New password:

Retype new password:

passwd: password updated successfully

Step 3: Once you set the user password the command will create a home directory for the user, copy several configuration files in the home directory and it will prompt you to set the new user’s information. If you want to leave all of this information blank just press ENTER to accept the defaults.

Output

Changing the user information for username

Enter the new value, or press ENTER for the default

    Full Name []:

    Room Number []:

    Work Phone []:

    Home Phone []:

    Other []:

Is the information correct? [Y/n]

Step 4: Add the user to the sudoers group. By default on Debian systems, members of the group sudo are granted sudo access. To add a user to the sudo group use the usermod command:

$ usermod -aG sudo [username]

Test the sudo access

Step 5: Switch to the newly created user.

$ su – [username]

Step 6: Use the sudo command to run the whoami command:

$ sudo whoami

If the user has sudo access then the output of the whoami command will be root.

 

To use sudo, simply prefix the command with sudo and space:

$ sudo ls -l /root

The first time you use sudo in a session, you will be prompted to enter the user password:

output

[sudo] password for username:

You can also string multiple commands together using sudo by separating them with a semicolon. For example:

Sudo whoami; hostname; ls

You can now log in to your Debian server with this sudo user account and use sudo to run administrative commands.

 

We hope that with the help of this article, you were able to better understand the concepts of a root user, sudo privileges and how they can be granted to different users. With the help of our simple six step tutorial, you can easily create a new user and add them to the sudoers file with just minutes. If you have any questions or suggestions, please leave them in the comment section below.

linda Y

linda Y

My name is Linda, I have Master degree in Information Technology Engineering. I have some experiences in working with Windows and Linux VPS and I have been working for 2 years on Virtualization and Hosting.