Ubuntu

How to Add User to Sudoers on Ubuntu 22.04

Just like in Windows we use an administrator account to log in to our system and perform actions as an administrator. Similarly, in Linux systems you can create an administrator account using the sudo command, letting you to run programs as root user. However, using root as your user can be a threat to the system, therefore, adding a user to sudoers is recommended.

Adding User to Sudoers on Ubuntu 22.04

If you wish to add a new user to sudoers on Ubuntu 22.04 then follow the guide provided below.

Pre-requisites

1. Ubuntu 22.04 (or any version) in a working state.

2. Root access to a user account.

Now that before we begin there are two methods with which you can add users to sudoers on Ubuntu 22.04. We will discuss each separately.

Method 1: Adding manually

This method requires you to follow certain steps which have been discussed below.

Step 1: Update the system

First validate that the system and the existing packages are updated. To update use the following commands.

$ sudo apt update && $ sudo apt upgrade -y

Output

System updated.

Step 2: Add new user

Once the system is updated, add a new user to sudoers by running the command given below on the terminal.

$ sudo add username

Here the new username that we will be adding is “newuser” as indicated in the output.

Output

Once you run the command enter the password for the current user. After that you will have to set a password for the new user. When the password is set, type the new username and press enter for default. At last, press ‘Y’ to continue.

Step 3: Verify addition

Now in order to evaluate whether the new user was added successfully or not, run this command.

$ cat /etc/passwd

Output

The new user was added successfully!

Step 4: Update the system

Once done, update your system once again by using the command provided below.

$ sudo apt update

Output

This is how you can add a user to sudoers on Ubuntu 22.04.

Method 2: Using usermod command

The usermod command is used to add or edit the sudoers user groups. The command below is used to add a new user to sudoers.

Step 1

$ sudo usermod -a -G sudo username

This time we will be adding a user named “john”. Here -a updates the changes to the present configuration, whereas, -G represents the name of the user community that the user should be added to.

Output

Step 2

Now to check if the user was successfully added or not we will use this command.

$ su username

Output

A new user was added with great ease.

Conclusion

To add a user to sudoers on Ubuntu 22.04 use the $ sudo adduser username command and to confirm the successful addition of the user run the command $ cat /etc/passwd. Another way of adding a user to sudoers is by using the usermod command which is; $ sudo usermod -a – G sudo username. The confirmation can be done using the command $ su username.

About the author

Naima Aftab

I am a software engineering professional with a profound interest in writing. I am pursuing technical writing as my full-time career and sharing my knowledge through my words.