When provisioning a new Ubuntu system, the main task to be done is adding and removing users. Each user can have various permission levels and specific settings for different command-line and GUI applications.
So in this article, we have explained how to add and remove user accounts on Ubuntu 20.04
Before we start
Let us see some points.
Only root or users with sudo rights can create and remove users.
The following two ways are used to create new users:
- From the command line.
- Through the GUI.
- How to Add and Delete Users on Ubuntu 18.04
- How To Add and Delete Users on Debian 10 Buster
- How To Install and Configure Ubuntu 20.04 with GNOME
Adding a User from the Command Line
In Ubuntu, there are a couple of command-line tools that you can do to create a new user account that is useradd and adduser.
useradd is a low-level utility. adduser is a script written in Perl that works as a friendly interactive frontend for useradd.
It is swift and easy to add a new user. Entreat the adduser command accompanied by the username. For example, to produce a new user account named username, you would work on the subsequent command
$ 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' ...
You will be examined a series of problems. Enter and validate the new user password. Answering all other questions is voluntary.
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]
In the end, you will be required to confirm that the information you typed is accurate or not
The command will generate the new user’s home directory and copy files from /etc/skel to it. Inside the home directory, the user can write, edit, and delete files and directories which they want.
If you need the new user to be capable of performing administrative tasks, you require to add the user to the sudo group :
$ sudo usermod -aG sudo username
Adding a User through the GUI
If you are not satisfied with the command line, you can add a new user account through the GUI also. To do so, you will need to follow the steps given below:
- The first step is to open the settings window and click on the “Users” tab.
- Then you will need to click on the “Unlock” button and open your user password when mentioned.
- After you enter the password, the “Unlock” button will convert to a green “Add User” button.
- Then you will need to click on the “Add User” button, and then Add user dialog will arrive:
- Then you will need to select whether the new user should be a standard or administrator user and insert information. Once done, then you will need to click on the “Add” button.
Removing a User from the Command Line
The following two commands are used in Ubuntu to delete a user account: userdel and its interactive frontend deluser.
To delete the user, request the deluser command and pass the username as the argument:
$ sudo deluser username
The above command will not remove the user files.
If you need to delete the user and its home directory and mail spool, use the –remove-home flag command for a better result.
Removing a User through the GUI
- The first step is to open the settings window and click on the “Users” tab.
- Then click on the “Unlock” button, and insert your user password when mentioned.
- Then click on the username which you want to delete, and you will observe a red “Remove User..” button on the base right corner, which indicated that the user could be removed.
- Then click the “Remove User..” button, and you will be mentioned whether to keep or delete the user home directory. By clicking on one of those buttons removes the user that you are willing to do.
Conclusion:
In this article, you have determined how to add and remove users in Ubuntu 20.04. Understanding how to add and remove users is one of the essential skills a Linux user should know.