How to Create a New sudo User in Ubuntu 20.04
This tutorial will teach you how to create a new sudo
user in any flavour of Ubuntu 20.04 desktop/server, without having to modify the /etc/sudoers
file.
1. CREATE A NEW USER
First, with the adduser
command, we will create a new user (userb
) on our system.
sudo adduser userb Adding user `userb' ... Adding new group `userb' (1002) ... Adding new user `userb' (1002) with group `userb' ... Creating home directory `/home/userb' ... Copying files from `/etc/skel' ... New password: Retype new password: passwd: password updated successfully Changing the user information for userb Enter the new value, or press ENTER for the default Full Name []: UserB Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] Y
Here, userb
is the new user we are adding. replace it with the username you wish to add.
2. ENABLE sudo FOR USER
If we add a user to the sudo group, they can use the sudo
command. We can use the usermod
command to add the just created, or an existing user to the sudo group.
sudo usermod -a -G sudo userb
Again, userb
is the example user we created in step 1. Replace it the username you wish to add to the sudo group.
Note: The -a
(append) switch is important. If it is not used while running this command, userb
will be removed from any group not listed after the -G
switch.
3. TESTING
In order to test the sudo powers of a user, first, we need to switch to that user. For that, we can use the su
command.
su userb
We can do a simple test with the ls
command to check if sudo is enabled for this user.
sudo ls -lah /root
If it gives out a permission denied
output, make sure that you did step 2 properly. Else, you will be able to see the contents of the /root
folder.