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
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
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
userb is the example user we created in step 1. Replace it the username you wish to add to the sudo group.
-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
In order to test the sudo powers of a user, first, we need to switch to that user. For that, we can use the
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