How to create a user with sudo access on Ubuntu 18.04
In this post we will explain to you how you create a user with sudo access on Ubuntu 18.04
Sudo stands for “superuser do” and allows users to run programs with the security privileges of another user. If no specific user is given, the sudo
command will execute as the superuser, hence the name.
A user with sudo access can be used to install, update, start and stop certain application that require elevated, root, privileges.
Before we can make a user with sudo access, we first need to create a normal user. In a later step we will later add this user to the sudo group.
In our example we will create a user called peter
. You can change this name to your liking.
$ sudo adduser peter
Note: sometimes you are not prompted to fill in a password. If that is the case, please make sure you are root user. As a root user, creating another user will ask you for a password.
Next, we will add peter to an existing group on our system. In this case the sudo group.
$ sudo usermod -aG sudo peter
What this snippet does is modifying (usermod) our user peter. We then give it the option -aG
. This will append one or more existing groups to peter. We only add the sudo group in our example.
To add more groups you need to separate the groups with a ,
, so
$ sudo usermod -aG sudo,custom_group peter
We are done adding the sudo group to peter. All that is left is to test if peter can use sudo commands. To test this we first need to log in as peter.
$ su peter
Now that we are logged in as peter, we can try to get root access by using a sudo command.
$ sudo su [sudo] password for peter: #
If you see the #
symbol it means you have successfully logged in as the root user.