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.
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.
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.
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.
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
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.
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.