How to Create Users and Manage Their Sudo Privileges on Ubuntu


create sudo user

The sudo command allows normal users to run programs which are only available to the root user. In this tutorial, we will show you how to create a system user and manage its sudo privileges on a Linux VPS running Ubuntu 16.04 as an operating system.

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

# adduser newuser

Feel free to replace newuser with the name of the system user you want to add. You will need to enter a password for your new user as well as you will need to enter some random user information. You can generate a strong password through 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 privileges to a system user in Linux

Once the system user is created go ahead and add it to the sudo group using 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 some command or program that is available only to the root user. For example, try to update the package index and to install the newest versions of all packages that are currently installed on your server.

sudo apt-get update
sudo apt-get upgrade

In case the sudo command is not installed on your server you will get the following error:

-su: sudo: command not found

This means you will need to install the sudo program in order to be able to run that command. Switch to your root account and run the following command:

# apt-get install sudo

You can verify that it is successfully installed using 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

Once the sudo program is installed on your Ubuntu VPS, switch to the new user and try to run the same commands again. You should not see the error message now and instead, you will be prompted to enter the password of the new system user.

Remove sudo privileges for a system user in Linux

In some cases, you may want to remove the sudo privileges for a specific system user. For that purpose you can use this command:

# deluser newuser sudo

Feel free to replace newuser with the name of the system user you want to modify. If you get the following message that means the system user has been successfully removed from the sudo group.

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

Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to help you add a new system user with sudo privileges on your server. They are available 24×7 and will take care of your request immediately.

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

Tutorials
Install Wagtail on CentOS 7
Tutorials
How to use rsync on a Linux VPS
Tutorials
How to Install Etherpad Lite on Debian Wheezy
There are currently no comments.

 
Free Migration to RoseHosting. Award Winning Linux VPS Hosting with Fully Managed Support. Coupon RHBLOG50 for 50% offOrder Now
+