How to Remove (Delete) a User on Ubuntu 16.04

User management includes removing users who no longer need access, removing their username and any associate root privileges are necessary for securing your server. Deleting a user’s access to your Linux server is a typical operation which can easily be performed using a few commands.  

Pre-flight Check

  • We are logged in as root on an Ubuntu 16.04 VPS powered by Liquid Web!

Step 1: Remove the User

Insert the username you want to delete by placing it after the userdel command. In our example, I’ll be deleting our user, Tom.

userdel tom

Simultaneous you can delete the user and the files owned by this user with the -r flag.  Be careful these files are not needed to run any application within your server.

userdel -r tom

If the above code produces the message below, don’t be alarmed, it is not an error, but rather /home/tom existed but /var/mail/tom did not.

userdel: tom mail spool (/var/mail/tom) not found

 

Step 2: Remove Root Privileges

By removing Tom’s username from our Linux system we are halfway complete, but we still need to remove their root privileges.

visudo

Navigate to the following section:

## Allow root to run any commands anywhere
root ALL=(ALL:ALL) ALL
tom ALL=(ALL:ALL) ALL

Or:

## User privilege specification
root ALL=(ALL:ALL) ALL
tom ALL=(ALL:ALL) ALL

With either result, remove access for your user by deleting the corresponding entry:

tom ALL=(ALL:ALL) ALL

Save and exit this file by typing :wq and press the enter key.

To add a user, see our frequently used article, How to Add a User and Grant Root Privileges on Ubuntu 16.04. Are you using a different Ubuntu version? We’ve got you covered, check out our Knowledge Base to find your version.

How to Add a User and Grant Root Privileges on Ubuntu 16.04

Ubuntu 16.04 LTS provides you the ability to add a user for anyone who plans on accessing your server.  Creating a user is a basic setup but an important and critical one for your server security. In this tutorial, we will create a user and grant administrative access, known as root, to your trusted user.

 

Pre-Flight Check

  1. Open a terminal and log in as root.  
  2. Work on a Linux Ubuntu 16.04 server

Step 1:  Add The User

Create a username for your new user, in my example my new user is Tom:

adduser tom

You’ll then be prompted to enter a password for this user.   We recommend using a strong password because malicious bots are programmed to guess simple passwords. If you need a secure password, this third party password generator can assist with creating one.

Output:

~# adduser tom
Adding user `tom' ...
Adding new group `tom' (1002) ...
Adding new user `tom' (1002) with group `tom' ...
Creating home directory `/home/tom' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Note
Usernames should be lowercase and avoid special characters. If you receive the error below, alter the username. ~# adduser Tom
adduser: Please enter a username matching the regular expression configured via the NAME_REGEX[_SYSTEM] configuration variable.  Use the `--force-badname' option to relax this check or reconfigure NAME_REGEX.

 

Prompts will appear to enter in information on your new user.  Entering this information is not required and can be skipped by pressing enter in each field.

Enter the new value or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:

 

Lastly, the system will ask you to review the information for accuracy.  Enter Y to continue to our next step.

Is the information correct? [Y/n]

 

Step 2: Grant Root Privileges

Assigning a user root access is to grant a user the highest power.  My user, Tom, can then make changes to the system as a whole, so it’s critical to allow this access only to users who need it. Afterward, Tom will be able to use sudo before commands that are usually designed to be used by the root user.

usermod -aG sudo tom

 

Step 3: Verify New User

As root, you can switch to your new user with the su – command and then test to see if your new user has root privileges.

su - tom

If the user has properly been granted root access the command below will show tom in the list.

grep '^sudo' /etc/group

Output:

sudo:x:27:tom

 

How To Assign a User to a MySQL Database in cPanel

This tutorial assumes you’ve already logged in to cPanel, and are starting on the home screen. Let’s learn how to assign a user to a database.

  1. Click the “MySQL Databases” icon.cpanel-pl-mysql-5-assignuser-02
  2. Under “Add User To Database”, select the user you want to add, and then select the database you want to add it to.cpanel-pl-mysql-5-assignuser-03
  3. When ready, click “Add”.cpanel-pl-mysql-5-assignuser-04
  4. Select the privileges you want to grant the user… in this case, let’s select “All Privileges”.cpanel-pl-mysql-5-assignuser-05
  5. Then click “Make Changes”.cpanel-pl-mysql-5-assignuser-06
  6. That’s it! The user has been assigned to the database.cpanel-pl-mysql-5-assignuser-07
  7. You can see the user assigned to the database in the table of databases.cpanel-pl-mysql-5-assignuser-08

 

How To Change Your cPanel Password

  1. This tutorial assumes you’ve already logged in to cPanel, and are starting on the home screen.cpanel-paperlantern-10-password--01
  2. Now let’s learn how to change the cPanel password.cpanel-paperlantern-10-password--02
  3. Click the “Change Password” icon.cpanel-paperlantern-10-password--03
  4. First enter your old, or existing password.cpanel-paperlantern-10-password--04
  5. Then enter and confirm a new password.cpanel-paperlantern-10-password--05
  6. Click “Change your password now”.cpanel-paperlantern-10-password--06
  7. That’s it! The cPanel password has been changed.

 

How to Remove (Delete) a User on Ubuntu 15.04

Users via Command Line 101: Basic User Interaction
I. How to Add a User and Grant Root Privileges on Ubuntu 15.04
II. How to Remove (Delete) a User on Ubuntu 15.04

Pre-Flight Check

  • These instructions are intended specifically for removing a user on Ubuntu 15.04.
  • I’ll be working from a Liquid Web Self Managed Ubuntu 15.04 server, and I’ll be logged in as root.

Continue reading “How to Remove (Delete) a User on Ubuntu 15.04”

How to Remove (Delete) a User on Ubuntu 14.04 LTS

Users via Command Line 101: Basic User Interaction
I. How to Add a User and Grant Root Privileges on Ubuntu 14.04 LTS
II. How to Remove (Delete) a User on Ubuntu 14.04 LTS

Pre-Flight Check

  • These instructions are intended specifically for removing a user on Ubuntu 14.04 LTS.
  • I’ll be working from a Liquid Web Core Managed Ubuntu 14.04 LTS server, and I’ll be logged in as root.

Continue reading “How to Remove (Delete) a User on Ubuntu 14.04 LTS”

How to Remove (Delete) a User on Ubuntu 12.04 LTS

Users via Command Line 101: Basic User Interaction
I. How to Add a User and Grant Root Privileges on Ubuntu 12.04 LTS
II. How to Remove (Delete) a User on Ubuntu 12.04 LTS
Pre-Flight Check
  • These instructions are intended specifically for removing a user on Ubuntu 12.04 LTS.
  • I’ll be working from a Liquid Web Core Managed Ubuntu 12.04 LTS server, and I’ll be logged in as root.

Continue reading “How to Remove (Delete) a User on Ubuntu 12.04 LTS”

How to Remove (Delete) a User on Fedora 21

Users via Command Line 101: Basic User Interaction
I. How to Add a User and Grant Root Privileges on Fedora 21
II. How to Remove (Delete) a User on Fedora 21
Pre-Flight Check
  • These instructions are intended specifically for removing a user on Fedora 21.
  • I’ll be working from a Liquid Web Self Managed Fedora 21 server, and I’ll be logged in as root.

Continue reading “How to Remove (Delete) a User on Fedora 21”