Create a Sudo User on Debian - Step by Step Process ?

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. 

Basically, Performing server administration as a non-root user is a best practice for security. 

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Sudo queries on Debian Linux System.

In this context, we shall look into how to create a new user on Debian system and make sudo user by giving it sudo access.


How to Create a Sudo User on Debian ?

By sudo user account you can execute administrative commands without a need to log in to root user account on your Debian server.

You need to perform the following steps to create a new user and give sudo access to it. You can skip create user steps if you wants to give sudo access to existing user.


  • Start by logging into your server as root user:
$ ssh root@server_ip_address

Create a new user account using adduser command. 

Replace linuxapt with your desired user name:

$ adduser linuxapt

It will prompt you to set new password and retype user password. It's recommended to set a strong password with combination of alphanumeric and special characters.

You will get the following output:

Adding user `linuxapt' ...
Adding new group `linuxapt' (1001) ...
Adding new user `linuxapt' (1001) with group `linuxapt' ...
Creating home directory `/home/linuxapt' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Once your password is updated successfully it will make a directory for a new user and make copy necessary configuration files. 

After that it will ask you to enter new user's information. These are optional so if you don't want to enter you can just skip by press Enter for each to set default.

You will see the following output:

Changing the user information for linuxapt
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]

Now, user is created and we will add new user to sudo group to grant sudo access. 

By default, members of the group sudo have sudo access on Debian systems:

$ usermod -aG sudo linuxapt


How to Verify sudo access ?

Login using new created user or you can switch to the new created user by type :

$ su - linuxapt

Use the sudo command to run the whoami command:

$ sudo whoami

If new user account have sudo access then output of given command will be root as below :

Output
root

Now you can use sudo by just type sudo before any command and give space :

$ sudo ls -la /root

First time it will prompt you to enter user password for that session :

Output
[sudo] password for linuxapt:


[Need urgent assistance in fixing Linux related errors? We can help you. ]

This article covers how to create a user with sudo privileges. You can now log in to your Debian server with this user account and use sudo to run administrative commands. Basically, In linux sudo is masterpiece to allow users to execute commands with another user's privileges, default is root user.


How to Create a new user account in Debian ?

Create a new user account using the adduser command. Don't forget to replace username with your desired user name:

$ adduser username


To Add the user to the sudo group

Use the usermod command:

$ usermod -aG sudo username

Related Posts