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:
Step 2: Create a Desired Username
Then create a new desired user by using the below-mentioned command:
Syntax
Example
Just to quote an example, here I have created a user with the name 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
Example
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
Example
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:
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.