How to add and remove users in Ubuntu 20.04

One of the first tasks in preparing a new Ubuntu system is adding and removing users. Each user can have different permission levels and specific settings for different command line and GUI applications.

This article explains how to add and remove user accounts in Ubuntu 18.04.

Before you start

Only root or users with sudo privileges can create and delete users.

New users can be created in two ways:

  1. From the command line.
  2. Through a graphical interface.

Adding a user from the command line

Ubuntu has two command line tools that you can use to create a new account: useradd and adduser.

useradd is a low-level utility. adduser is a script written in Perl that acts as a friendly interactive interface for useradd.

Adding a new user is quick and easy, just run the adduser command followed by the username. For example, to create a new user account named username, you would run:

sudo adduser username

Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...

You will be asked a series of questions. Enter and confirm the new user password. All other questions are optional.

Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] 

At the end, you will be asked to confirm that the information you entered is correct.

The command will create the new user’s home directory and copy / etc / skel. In the home directory, the user can write, edit and delete files and directories.

If you want the new user to be able to perform administrative tasks, you need to add the user to the sudo group:

sudo usermod -aG sudo username

Adding a user through the graphical interface

If you are not comfortable using the command line, you can add a new user account through the graphical interface. To do this, follow these steps:

  1. Open the settings window and go to the “Users” tab.
  2. Click the “Unblock” button and enter the user password when prompted. After entering the password, the Unblock button will change to a green Add User button.
  3. Click the Add User button, the Add User dialog box appears:
  4. Select whether the new user should be a standard user or an administrator and enter the information. After that click the “Add” button.

Removing a user from the command line

On Ubuntu, you can use two commands to remove a user account: userdel and its interactive interface deluser.

To remove a user, call the deluser command and pass the username as an argument:

sudo deluser username

The above command does not delete user files.

If you want to remove a user, their home directory and mailbox, use the –remove-home flag:

sudo deluser --remove-home username

Removing a user through the graphical interface

  1. Open the settings window and go to the “Users” tab.
  2. Click the “Unblock” button and enter the user password when prompted.
  3. Click on the username you want to delete and in the lower right corner you will see a red “Delete user …” button.
  4. Click the “Remove User …” button and you will be prompted to save or remove the user’s home directory. Clicking on one of these buttons deletes the user.

Output

We showed you how to add and remove users in Ubuntu 20.04. Knowing how to add and remove users is one of the basic skills a Linux user should know.

Feel free to leave comments if you have questions.

Sidebar