How to Add User to Sudoers on Ubuntu 22.04

Being an administrator, it is a good practice to use an administrative account to manipulate the system settings and files. On Ubuntu 22.04, either you must log in as root or you must have the root privileges via sudo. The sudo (superuser do) privileges can be granted to any user on the system or any newly created user.

In this article, we have demonstrated various methods to add the user to the sudoers file on Ubuntu 22.04.

Method 1: How to add a user to Sudoers on Ubuntu 22.04 using Command Line Interface?

A user can be added to Sudoers on Ubuntu 22.04 through the Command-Line-Interface using the usermod command. A usermod is a system administrator command. However, for adding a user to Sudoers, go along with the below-mentioned step-wise procedure.

Step 1: Create a new user

You can create a new user or add the existing user to the Sudoers files. Moreover, if you want to create a new user for adding to Sudoers, run the following command:

$ sudo adduser newuser1

After entering the new user password and full name, a new user is created with the name “newuser1”.

Step 2: Add newuser1 to Sudoers

To add the newuser1 to Sudoers group, run the following command:

$ sudo usermod -aG sudo newuser1
$ groups newuser1

Here, -a indicates the updates, and G indicates the name of the user community. The output showed that the user is added to the Sudoers.

Step 3: Verify by switching the User

To verify the changes for a new user, run the following command:

$ su newuser1

It can be observed from the output that the newuser1 can perform the operations as a root user.

How to remove a user from Ubuntu 22.04?

The command mentioned below will delete the “newuser1” from Ubuntu 22.04:

$ sudo deluser newuser1

The output showed that the user “newuser1” has been removed successfully.

Method 2: How to add user User to Sudoers on Ubuntu 22.04 using Graphical User Interface?

The Command Line Interface (GUI) utility provides the ease to use the system and install several applications on Ubuntu 22.04. It helps in creating and adding a new user on Ubuntu 22.04. To fulfil this purpose, follow the provided guide as mentioned below:

Step 1: Open settings

First, click on Activities, navigate to the search bar and write settings as follows:

By clicking on settings, the following interface will be opened:

Step 2: Search Users

Now, scroll down the left pan to search the Users and click on it. The user-related settings will appear on the right window pane:

Step 3: Unlock the user settings

In the Users tab, go towards the Unlock option on the right side of the window and click on it:

The following authentication window will open. Enter the specified Password and push on Authenticate button:

Step 4: Add a new user to Sudoers

After the authentication, you can add a new user to Sudoers on Ubuntu 22.04 by clicking on the Add User button in the following window:

The following window will appear where you need to perform the following changes:

  • set the Account Type to Administrator for the root privileges,
  • Choose the Full Name, Username (we have chosen itxlinuxfoss as the username)
  • Set a Password for the user

Lastly, click on the “Add” button:

You need to provide the password of the current user to apply the changes:

It will add a new user account that has administrative privileges:

You can see that a new user is created successfully on Ubuntu 22.04.

Congratulations! You have learned the different methods to add users to Sudoers on Ubuntu 22.04 successfully.

Conclusion

A user can be added to Sudoers on Ubuntu 22.04 using the Command Line Interface (sudo usermod -aG sudo <newuser>) or Graphical User Interface (Users settings). This write-up illustrated the vast knowledge to add users to Sudoers on Ubuntu 22.04. This can be a newly created user or an existing user.