Sep 20, 2023 4 min read

How to Add and Remove Users on Ubuntu 20.04

Add and Remove Users on Ubuntu 20.04 with our step-by-step tutorial. It is the process of granting or revoking access to users within a system.

Add and Remove Users on Ubuntu 20.04
Table of Contents

Introduction

Add and remove users refers to the process of granting or revoking access to individuals within a system or platform. Whether it's an online service, software, or website, user management plays a crucial role in maintaining security and controlling user privileges.

By adding users, administrators can grant authorized individuals access to specific resources, while removing users ensures that their access is terminated when necessary. Efficient user management enables streamlined collaboration, enhanced security, and personalized experiences.

This tutorial will show you how to create and delete user accounts in Ubuntu 20.04.

Advantages of Add and Remove Users

  1. Enhanced Security: Add and remove users allows administrators to control access, safeguarding sensitive information and preventing unauthorized entry.
  2. Streamlined Collaboration: Granting access to relevant users fosters teamwork and enables efficient collaboration on shared projects.
  3. User Privilege Control: Administrators can assign specific roles and permissions to users, ensuring they have appropriate access to resources.
  4. Personalized Experiences: By managing users, platforms can tailor content and features based on individual preferences, delivering a personalized user experience.
  5. Efficient User Onboarding/Offboarding: Adding and removing users simplifies the process of onboarding new users and terminating access for departing individuals, saving time and resources.

Prerequisites to Add and Remove Users on Ubuntu 20.04

Users can only be created and removed by root or users with sudo privileges. There are two methods for adding new users:

  1. From the command line.
  2. Through the GUI.

Adding a User from the Command Line

You can create a new user account on Ubuntu using two command-line tools: useradd and adduser.

useradd is a command-line utility. adduser is a Perl script that serves as a friendly interactive frontend for useradd.

Adding a new user is simple, simply run the adduser command, followed by the username. For example, to create a new user account called username, type:

sudo adduser username
Output

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' ...

A series of questions will be posed to you. Enter the new user password and confirm it. It is optional to respond to all other questions.

Output

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] 

You'll be asked to confirm that the information you entered is correct at the end.

The command will create a home directory for the new user and copy files from /etc/skel to it. The user can write, edit, and delete files and directories in his or her home directory.

You must add the new user to the sudo group if you want the user to be able to perform administrative tasks:

sudo usermod -aG sudo username

Adding a User through the GUI

If you are not familiar with the command line, you can create a new user account using the GUI. To do so, follow these steps:

  1. Click on the “Users” tab in the settings window after opening it.
  2. When prompted, click the “Unlock” button and input your user password.
  3. Click on the “Add User” button, and the Add user dialog will appear:
  4. Select whether the new user should be a standard or administrator user and enter information. Once done, click on the “Add” button.

Removing a User from the Command Line

To delete a user account on Ubuntu, use the userdel command and its interactive frontend deluser.

To delete a user, use the deluser command with the username as an argument:

sudo deluser username

The above command will not delete the user files.

Use the --remove-home flag to delete the user, as well as its home directory and mail spool:

sudo deluser --remove-home username

Removing a User through the GUI

  1. Click on the “Users” tab in the settings window after opening it.
  2. When prompted, click the “Unlock” button and input your user password.
  3. Click on the username you want to delete, and you will see a red “Remove User…” button in the bottom right corner.
  4. 4.  When you click on the username you want to remove, a red “Remove User…” button will appear in the bottom right corner.

FAQs to Add and Remove Users on Ubuntu 20.04

Can I specify user privileges during the user creation process?

Yes, while adding a user, you can assign specific user privileges, such as granting administrative access or assigning them to a particular group, using the appropriate options during the adduser command.

What happens to the user's files when they are removed?

By default, the user's home directory and files are not deleted when the user is removed. However, you can use the --remove-home option with the deluser command to remove the user's home directory as well.

Can I add multiple users at once?

Yes, you can add multiple users simultaneously by running the adduser command for each user, providing their respective usernames and details.

How can I see a list of all users on my Ubuntu system?

To view a list of all users, you can use the "cat" command to read the /etc/passwd file, which contains information about all users on the system. Alternatively, you can use the getent passwd command.

Can I change a user's password after adding them?

Yes, you can change a user's password using the passwd command. Run sudo passwd username and follow the prompts to set a new password for the specified user.

What if I need to remove a user's account and their files at once?

To remove a user account and their files simultaneously, use the --remove-all-files option with the deluser command. For example, sudo deluser --remove-all-files username will delete the user account and their home directory.

Conclusion

In this tutorial, we'll show you how to add and remove users in Ubuntu 20.04. One of the fundamental skills a Linux user should have is the ability to add and remove users.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.