How To Create a Sudo User on Ubuntu

Here is how you can create a sudo user on Ubuntu. In particular on Vultr’s instance i.e. Ubuntu 16.04 LTS / 18.04 LTS / 18.10 / 22.04 LTS.

Prerequisites

  • Have an Ubuntu 16.04 x64 / 18.04 x64 / 18.10 x64 / 22.04 X64 instance.
  • Logged in as a root with sudo privileges.

To get started with the creation of a new user, follow the steps below:

Logging Into Your Server via Secure Shell (SSH)

SSH into your server as the root user:

ssh [email protected]_server_ip_address

Create a Sudo User on Ubuntu

Create a new user account with the adduser command and use a strong password.

adduser mohsin

and the output will be

Adding user `mohsin' ...
Adding new group `mohsin' (1001) ...
Adding new user `mohsin' (1001) with group `mohsin' ...
Creating home directory `/home/mohsin' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully

After that, you will be asked to enter values for the user information e.g. Full Name, Room Number etc, or press ENTER to leave those fields blank.

Changing the user information for mohsin
Enter the new value, or press ENTER for the default
        Full Name []: Mohsin Rafique
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y

Add the User to the Sudo Group

Use the following command to add the user to the sudo group:

adduser mohsin sudo

and the output will be

Adding user `mohsin' to group `sudo' ...
Adding user mohsin to group sudo
Done.

Test Sudo Access

Now switch to the new user with the following command

su - mohsin

Verify with the following command:

whoami

and the output will be:

mohsin


Now test sudo access with sudo whoami, which should return root.

sudo whoami

and the output will be

[sudo] password for mohsin:

After giving the password, output will be

root

Note: Be sure to replace mohsin with the username you just added.

Conclusion

Now you have learned how to create a new user with sudo access on Ubuntu. If you have questions feel free to leave a comment below.

Related Post

How to Switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10 with Nginx

Here is you will learn how to switch WordPress from PHP 7.2-FPM to PHP 7.3-FPM on Ubuntu 19.10. In particular on Vultr‘s instance i.e. Ubuntu 19.10.

How to Install MariaDB on Ubuntu

Here is how you can install MariaDB on Ubuntu. In particular on Vultr’s instance i.e. Ubuntu 16.04 LTS / 18.04 LTS / 20.04 LTS / 22.04 LTS.

Leave a Reply