To create a new sudo user in Linux, you need to log in with the root user. You will learn step by step how to create a new sudo user in Ubuntu. If you know some steps you can directly switch to the next one.

What is a sudo user?

Before creating a user we will first discuss some basics about the sudo user in Linux.

The sudo user is nothing but the user who has permission to run the Linux commands which can not be executed with the regular user.

That means the sudo user in Linux executes the commands that need the root user privilege. Sudo users can also run the commands on behalf of other regular users.

Putty - Login to the server
Putty – Login to the server

Step1: Login to the server

To create a new user log into the system with the root user.

You can also execute the same commands which can’t be run with regular users, with the sudo user once you create one.

So for creating the user login to your server with putty with the root user.

Step2: Create a new user in the Linux (Ubuntu)

You can also execute the same commands which can’t be run with regular users, with the sudo user once you create one

So for creating the user login to your server with putty with the root user.

Create a new user on Ubuntu (Linux)
Create a new user on Ubuntu (Linux)

Create a new user

We will create a user named “new_user”

  • type the ssh command below.

$ adduser new_user

Replace “new_user” with the username you want to add.

Then provide the password for the new_user

  • Then again type the password to confirm the password prompt.
  • After the password, it will ask for some information about the “new_user” like Full name, Room no, Work Phone, Home Phone, etc. Give the required information, or to skip with default values just press Enter.
  • After providing all the necessary information, it will again ask for confirmation, press Y and Enter to confirm the details for the new_user.

Now your new_user is created.

Step 3: add this user to the sudoers list. (Important step to create a sudo user in Ubuntu)

Run the following command to add a user to the sudoers list, this will make your sudo user run the sudo commands. This is the important step to create a sudo user in Ubuntu. If you already have a user and want to make it a sudo user you can directly run the below command so that your normal user would become the sudo user.

$ usermod -aG sudo new_user

Don’t forget to replace the new_user with your username.

This command will add a user to the sudoers list.

You can confirm if the user is really added to the sudoers list or not by the following command:

$ -l -U new_user

If you get the output content like:

User new_user may run the following commands on <your_os>:
(ALL : ALL) ALL

Then we can say that the user is successfully added to the sudoers list which means it can run commands with sudo privileges.

Step 4: Run the sudo commands with the new sudo user

Logout root user from the server and log in with the new_user

Now you can run any sudo commands with this user. You can also use this user to create new sudo users,

Add a new user with the sudo user

For executing the commands you just need to add the “sudo” word before any command.
Like:

$ sudo adduser new_user2

This will create a new user in the system with the name “new_user2”

Grant the sudo privilege to the user with the sudo user

$ sudo usermod -aG sudo new_use

Now your second user is also a sudo user. You can use this user to execute the sudo commands.

Remove/ Revoke the sudo permission from the user

If you want to remove the sudo access from the user type the ssh command below:

$ sudo gpasswd -d new_user2 sudo

This will remove the sudo access from the user and the user will become a normal/regular user. You can not now run the sudo commands with new_user2.

Your feedback is highly appreciated!