How to Create a Sudo User on Ubuntu and other Debian-based Linux distributions

The sudo command is intended to permit users to run programs with the security privileges of another user, by default the root user.
In this article, you will learn how to create a new user with sudo access on Ubuntu OS. You would then be able to utilize this user to run admin commands without a need to signing in to your Ubuntu system as a root user.
Steps to Create a Sudo User
Follow the steps below to create a new user and give it sudo privileges. If you need to enable sudo access to an existing user, jump to step 3.
1. Log in to your server.
Log in to your system as the root user:
ssh root@server_ip_address2. Create a new user
use adduser command to create a new user as shown below, and don't forget to replace username with the user name that you want to create:
adduser usernameYou will be prompted to set and confirm the new user password.
# 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 successfullyOnce you set the password the command will make a home directory for the user, copy a few configuration files in the home directory, and prompts 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]3. Add the new user to the sudo group
To add the user you created to the sudo group use the command:usermod
usermod -aG sudo usernameTest the sudo access
Switch to the newly created user:
su - usernameUse to run the sudo command:whoami
sudo whoamiIf the user have sudo privileges then the output of the command will be “whoamiroot”:
# Output:
root
Please login or create new account to add your comment.