Ubuntu, just like any other operating system, is a multi-user operating system where each user can have different sets of privileges. They can use these privileges to execute commands for various applications.
In this tutorial, you will learn how to add and delete users on Ubuntu 18.04 LTS.
To add and remove users on Ubuntu, you must be logged in as root or a user with sudo privileges.
Add A New User
There are two ways to create a new user account on Ubuntu:
- Add user from the command line
- Add user through GUI (Graphical User Interface)
1. Add a user from the command line
For adding new users on Ubuntu, there are two Linux commands available:
useradd is the low-level command that is used for creating user accounts on Linux and other Unix-like operating systems. The
adduser is very much similar to
useradd, because it is just a symbolic link to it.
Let us use
adduser command to create a new user account with name
$ 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' ...
Afterward, you will be asked to enter the user details. Only the password is required. All other fields are optional:
New password: Retype new 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] Y
Y to confirm the information. This will create the new user's home directory, and copy files from
/etc/skel directory to the user's home directory.
Within the home directory, the user can add, edit, and delete files and directories. If you want to grant administrative rights to newly created user, add it to the sudo group:
$ sudo usermod -aG sudo username
Don't forget to replace
usernamekeyword in above commands with the user name that you want to create.
2. Add a user from the GUI
If the command line is not your favorite thing, you can add a new user account from the GUI.
Open the Account Settings dialog either through Activities screen (search users and then click on Add or remove users and change your password) or by clicking the down-arrow located at the top rIf you had previously configured sudo privileges for the user you deleted, you may want to remove the relevant line again by typing:
ight corner of your Ubuntu screen. Click your username and then click again on Account Settings.
In the next window, click on Unlock button and enter your password when prompted:
Once you enter the password, the Unlock button will change to a green Add User button. Click on this button to open the below Add User dialog:
Enter the user information (full name, username, password) and select whether the new user should be a standard or administrator user. Next, click on Add button and you are done.
Delete A User
If a user account is no longer needed, you can remove it either from the command line or through GUI.
1. Delete a user from the command line
There are two Linux commands available that you can use to delete a user account:
userdel is a low-level command similar to
deluser is a friendly symbolic link to it.
To delete user, without removing the files in user's home directory, run the following command:
$ sudo deluser username
If you want to delete the user's home directory too along with user account, issue the following command with
$ sudo deluser username --remove-home
If you had previously included the deleted user to sudo group, you can remove it by typing:
$ sudo gpasswd -d username sudo
Delete a user from the GUI
Follow the above steps to open the Account Settings dialog. Click on the Unlock button and enter your password when prompted. Once you enter the password, you will see a red Remove User... button on the bottom right corner:
Click on the red button and you will be prompted to choose whether to delete or keep the user's home directory. Clicking on one of these buttons will remove the user account.
In this article, you have learned how to add and remove users on your Ubuntu 18.04 machine. You should now have a fairly good understanding of how to manage user accounts on Ubuntu.
The same commands can be applied to add and delete users on any Ubuntu-based distribution, including Debian, Kubuntu, and Linux Mint.
Better user management can prevent many destructive things and allows you to control users access by giving them the rights they need to complete the task.
Need help to start a new Spring Boot or MEAN stack project? I am available for contract work. Hire me to accomplish your business goals with engineering and design. Let’s talk about your project: firstname.lastname@example.org.