How to create a user and manage with Sudo privileges in Ubuntu

The Sudo command allows regular users to run programs that are only available to the superuser. In this tutorial, we are going to show you how to create a system user and manage your Sudo privileges on a Linux – VPS running Ubuntu 16.04 as the operating system.

First of all, connect to your Linux server using SSH and add a new system user:

# adduser newuser

You can replace newuser to any name of the system user you like. You will need to enter a password for the new user and also you will need to enter some user information. You can create a strong password using the command line.

# adduser newuser
Adding user `newuser' ...
Adding new group `newuser' (1001) ...
Adding new user `newuser' (1001) with group `newuser' ...
Creating home directory `/home/newuser' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for newuser
Enter the new value, or press ENTER for the default
        Full Name []: New User
        Room Number []: 101
        Work Phone []: 123456
        Home Phone []: 123456
        Other []:
Is the information correct? [Y/n] y

Add sudo system user privileges to Linux

After the system user is created go ahead and add it to the group sudousing the following command:

# usermod -aG sudo newuser

Then use the su command to switch to the new user:

# su - newuser

Now you can try to run any command or program that is available only to the superuser. For example, try updating the package index and installing new versions of all packages currently installed on the server.

sudo apt-get update
sudo apt-get upgrade

In case the Sudo command is not installed on your server, you will receive the following error message:

-su: sudo: command not found

This means that you will need to install the Sudo program in order to be able to execute this command. Switch to superuser and run the following command:

# apt-get install sudo

You can verify that it has been installed successfully with this command:

# dpkg -l | grep -i sudo

The output should be similar to the one below:

# dpkg -l | grep -i sudo
ii  sudo                          1.8.16-0ubuntu1.3                     amd64        Provide limited super user privileges to specific users

After Sudo is installed on your Ubuntu VPS, switch to the new user and try running the same command again. You should no longer see the error message, and instead, you will be prompted to enter the password for the new system user.

Remove sudo privileges for system user in Linux

In some cases, you may want to remove the Sudo privileges for a specific system user. The following command can be used for this purpose:

# deluser newuser sudo

You can replace newuser to the name of the system user you want to change. If you receive the following message, the system user has been successfully removed from the Sudo group.

# deluser newuser sudo
Removing user `newuser' from group `sudo' ...
Done.

PS. If you liked this post, you can share it with your friends on social networks using the buttons below or leave a reply in the comments section.

Sidebar