Ubuntu

How To Create A New Sudo Enabled User on Ubuntu 22.04

In most Linux-based systems including Ubuntu, the root user has all the administrative-level system privileges. But many times, multiple users use the system and to perform administrative tasks they are required to be sudo enabled so that they won’t get authentication errors.

If you are the one experiencing the authentication error, follow this article’s guidelines to learn the method to create a new sudo-enabled user without modifying the sudoers file.

How To Create a New Sudo-Enabled User on Ubuntu 22.04

To create a sudo-enabled user on Ubuntu 22.04, follow the below-written steps:

Step 1: Switch to “root” User

To create a “sudo” enabled user, first switch to the root user of the Ubuntu system by running the below-mentioned command:

$ sudo su root

Step 2: Create a Desired Username

Then create a new desired user by using the below-mentioned command:

Syntax

# adduser <username>

Example

Just to quote an example, here I have created a user with the name myuser:

# adduser myuser

Step 3: Set a Password

After running the above command, the system will ask you to set a new password. Here, I recommend setting a strong password with at least 8 characters in it for better security.

Then retype the password for confirmation purposes, after confirming, the password for the new user will be updated in the system.

Step 4: User Information

The system will ask for some information about the user like the full name, phone number and other such information, this is totally up to the user if they want to enter this information or set them to default by pressing the Enter key.

Step 5: Add User to “sudo” Group

To assign “sudo” privileges to the created user, you are required to add it to the “sudo” group. For that use the below-written command:

Syntax

# usermod -aG sudo <username>

Example

# usermod -aG sudo myuser

Step 6: Verifying

Once the user is created and added to the user group, it’s time to verify if the created user is sudo enabled or not. For this purpose, let’s switch to the created user by using below-mentioned command:

Syntax

# su - <username>

Example

# su - myuser

Then run the below-written command which is basically a command to list the content present inside the root directory and is only accessible to root or a user having root privileges:

$ sudo ls -la /root

In the below image you can see that the command has displayed output successfully, which verifies that the created user is sudo enabled.

Conclusion

To create a sudo-enabled user, first switch to the “root” user. Then create a desired user by using the adduser command, and set a password for the created user. Next, add the user to the sudo group and finally verify by running any root command after switching to the created user.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.