Sep 19, 2023 4 min read

How to Add and Delete Users on Ubuntu 18.04

Add and Delete Users on Ubuntu 18.04 with our step-by-step tutorial. It is a multi-user operating system, just like any other Linux distribution.

Add and Delete Users on Ubuntu 18.04
Table of Contents

Introduction

Before we begin talking about how to add and delete users on Ubuntu 18.04, let's briefly understand – What is Ubuntu?

Ubuntu is a multi-user operating system, just like any other Linux distribution. For numerous command-line and GUI apps, each user might have varying permission levels and particular settings.

One of the essential skills required for a Linux user is the ability to add and remove users.

In this tutorial, you will add and delete users on Ubuntu 18.04. We will also address a few FAQs on how to add and delete users on Ubuntu 18.04.

Advantages of Ubuntu

  1. User-friendly: Ubuntu offers a simple and intuitive interface, making it user-friendly for both beginners and experts alike.
  2. Wide community support: The large Ubuntu community provides extensive online resources, documentation, and forums for easy troubleshooting and assistance.
  3. Stability and reliability: Ubuntu is known for its stability and long-term support (LTS) releases, ensuring a reliable and secure operating system.
  4. Vast software repository: The Ubuntu Software Center offers a vast library of free and open-source software, making it easy to find and install applications.
  5. Customizability: Ubuntu allows users t2o personalize their desktop environment, providing flexibility and freedom to adapt the system to individual needs.

Prerequisites

You must be logged in as root or a user with sudo rights to create and remove users.

How To Add User on Ubuntu

On Ubuntu, there are two ways to establish a new user account:

  • Using the command prompt
  • Through the user interface

Add a New User from the Command Line

To create a new user account On Ubuntu, you can use the useradd and adduser command-line utilities.

adduser is a nice interactive frontend to useradd written in Perl, while useradd is a low-level application for adding users.

To use the adduser command to create a new user account named 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 asked of you. All other fields are optional, except for the password.

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] 

Finally, enter Y to confirm that the information is correct.

The command will create the new user's home directory and copy files from the /etc/skel directory into it. The user can write, edit, and delete files and folders in their home directory.

sudo access is allowed to the members of the sudo group by default on Ubuntu.

Add the newly formed user to the sudo group if you want the user to have administrative rights:

sudo usermod -aG sudo username

Add a New User through the GUI

If you prefer not to use the command line, you can create a new user account using the GUI.

  1. Search for "users" in the Activities screen and select "Add or remove users and change your password."
  2. Click the "Unlock" button in the new window, then enter your user password when requested.

The "Unlock" button will change to a green "Add User" button once you enter the password.

3. The Add User dialog will appear when you click the "Add User" button.

4. Choose whether the new user should be a standard or administrator user, then fill out the form. When you're finished, click the "Add" button.

How To Delete a User

You can delete the user account from the command line or using the GUI if it is no longer required.

Delete a User from the Command Line

Userdel and deluser are two command-line utilities that can be used to delete a user account. On Ubuntu, the deluser command is preferable over the low-level userdel command because it is more user-friendly.

To delete the user, without destroying the user files, run:

sudo deluser username

Use the --remove-home flag to destroy the user, including its home directory and mail spool:

sudo deluser --remove-home username

Delete a User through the GUI

  1. Search for "users" in the Activities screen and select "Add or remove users and change your password."
  2. Click the "Unlock" button in the new window and input your user password when required. The "Unlock" button will change to a green "Add User" button once you enter the password.
  3. When you click on the username you want to delete, a red "Remove User..." button appears in the bottom right corner.
  4. When you click the "Remove User...," you'll be asked whether you want to keep or delete the user's home directory. The user will be removed if one of those buttons is clicked.

FAQs to Add and Delete Users on Ubuntu 18.04

Can I specify a home directory for a new user during creation? 

Yes, you can specify a custom home directory using the adduser command with the --home option. For instance: sudo adduser newusername --home /path/to/directory.

Can I assign a password while adding a user? 

Yes, you can set a password for the new user during the creation process. After running adduser, you will be prompted to enter the password.

How can I add a user to a specific group? 

To add a user to a particular group, use the adduser command followed by the username and the group name. For example: sudo adduser username groupname.

What permissions are necessary to add or delete a user? 

You will need administrative privileges to add or delete users. Use the sudo command before the user management commands to execute them with root privileges.

Can I set a password for a new user during creation? 

Yes, you can set a password for a new user by using the adduser command with the --password option. For example: sudo adduser newusername --password password_here.

What if I want to keep a user's home directory intact when deleting the user?

 By default, the deluser command preserves the user's home directory. If you want to delete the user but keep the home directory, simply omit the --remove-home option.

How can I list all the users on Ubuntu 18.04? 

You can use the cut and grep commands together to list all the users on Ubuntu. Run the following command: cut -d: -f1 /etc/passwd | grep -vE "nologin|false".

Conclusion

You learnt how to add and remove users on Ubuntu in this tutorial. Any Ubuntu-based distribution, including Debian, Kubuntu, and Linux Mint, can use the same commands.

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.