How to Create a Sudo User on Ubuntu 20.04 LTS
The root user, which is the default user created with administrative privileges, is locked in Ubuntu by default, meaning you cannot log in to the system as a root user. The
sudo command comes into play in such cases, when you need to perform administrative tasks with your own user. Basically it allows a normal user to run commands with root privileges.
Creating Sudo User
The first step is to create a user using the command
adduser. Enter the password and other optional details when prompted.
sudo adduser <username>
Note that only root has the privileges of adding new users to the system. Hence we ran the command with
sudo. That means, your user should already have
sudo privileges if you want to create a new sudo user.
Next step is to add this user to the group
sudo, which will assign all the sudo privileges to the user.
sudo adduser <username> sudo
The user has now been added to the group sudo. Let’s verify if the user has sudo privileges.
Test the Sudo User
Switch to the newly created user with the command
su - <username>
We have logged in as the new user. Notice that the prompt has also changed showing the name of the new user.
Note that once we logged in as the new sudo user, the welcome text appeared advising on how to use the command
sudo. This means the user is part of sudo group.
Now let’s run a command with sudo with this user, and let’s see if it works. We will try to create a directory called
/etc, for which we need
sudo access as only root has privileges to modify
sudo mkdir /etc/tmp
As we can see with
ls, the directory
tmp has been successfully created in
In this article, we have seen how to create a new sudo user. If a user has to be given sudo privileges for a limited time, you can remove the user from sudo group to revoke his/her privileges. Use command
deluser to remove a user from the sudo group.