How to Add and Remove Users on Ubuntu 20.04

DJ
Developers Journal
Published in
4 min readJan 18, 2022

--

The very first task when you are provisioning a new Ubuntu system is adding and removing users. Users have different permission levels and specific settings for various GUI (Graphic User Interface) and CLI (Command Line Interface) applications.

In this journal entry, we will be having an understanding on how we can add and remove user(s) account on Ubuntu 20.04.

Before We Begin

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

New users can be created in two ways:

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

Adding a User from the Command Line

In Ubuntu, there are two command-line tools that you can use to create a new user account: useradd and adduser.

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

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

sudo adduser djuser

OUTPUT:

Adding user ‘djuser’ …
Adding new group ‘djuser’ (1001) …
Adding new user ‘djuser’ (1001) with group ‘djuser’ …
Creating home directory ‘/home/djuser’ …
Copying files from ‘/etc/skel’ …

You will be asked a series of questions. Enter and confirm the new user password. Providing an answer to all other questions is optional.

New password:
Retype new password:
passwd: password updated successfully
Changing the user information for djuser
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]

After entering all the information, you’ll be prompted to confirm that the information you entered is correct.

The command will create the new user’s home directory, and copy files from /etc/skel to it. Within 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 djuser

Adding a User through the GUI

If CLI (Command Line Interface) is not your forte and you are more comfortable working with the GUI, then you can follow below steps:

  1. Open the settings window and click on the “Users” tab.
  2. Click on the “Unlock” button, and enter your user password when prompted.

After providing the password, the “Unlock” button will change to a green “Add User” button.

3. Click on the “Add User” button. This will open up new dialog window where we can provide the new User details.

4. You can select whether the new user will have Standard or Administrator privileges.

5. Once you are done with the information, click on the “Add” button.

Removing a User from the Command Line

In Ubuntu, you can use two commands to delete a user account: userdel and its interactive frontend deluser.

To delete the user, invoke the deluser command and pass the username as the argument:

sudo deluser djuser

The above command will remove the user identity but not the user files.

If you want to delete the user and its home directory and mail spool, use the — remove-home flag:

sudo deluser — remove-home djuser

Removing a User through the GUI

  1. Open the settings window and click on the “Users” tab.
  2. Click on the “Unlock” button, and enter your user password when prompted.
  3. Click on the username you want to delete, and you will see a red “Remove User” button on the bottom right corner.

4. Click the “Remove User” button, and you will be prompted whether to keep or delete the user home directory. Clicking on one of those buttons removes the user.

Conclusion

Adding and Removing users in a Linux environment is one of the basic skills for an Administrator/User of Linux should possess. In this journal entry, we can across the steps on how we can add and remove users in Ubuntu 20.04.

Please feel free to leave a comment if you have any questions.

--

--

DJ
Developers Journal

Journal for developers who are looking for all the latest information’s, tutorials, what’s new, how-to, and so much more. https://developersjournal.in