Ubuntu, like any other operating system, is a multi-user operating system where every user can have different 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.
Prerequisites
To add and remove users on Ubuntu, you must be logged in as root or a user with sudo privileges on a Ubuntu 18.04 machine (get one from DigitalOcean).
Add A New User
There are two ways to create a new user account on Ubuntu:
- Add a user from the command line
- Add user through GUI (Graphical User Interface)
1. Add a user from the command line
There are two Linux commands to add new users on Ubuntu: useradd
and adduser
.
The useradd
is the low-level command for creating user accounts on Linux and other Unix-like operating systems. The adduser
is similar to useradd
because it is just a symbolic link.
Let us use the adduser
command to create a new user account with the name username
:
$ sudo adduser username
Adding user `username' ...
Adding a 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
Enter Y
to confirm the information. This will create the new user's home directory and copy files from the /etc/skel
directory to the user's home directory.
The user can add, edit, and delete files and directories in the home directory. If you want to grant administrative rights to a newly created user, add it to the sudo group:
$ sudo usermod -aG sudo username
Don't forget to replace the
username
keyword in the above commands with the user name 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 the Activities screen (search users and then click on Add or remove users and change your password) or by clicking the down arrow at the top right corner of your Ubuntu screen. Click your username and then click again on Account Settings.
In the next window, click on the 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 the Add button, and you are done.
Delete A User
If a user account is no longer needed, you can remove it 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: deluser
and userdel
. The userdel
is a low-level command similar to useradd
, whereas deluser
is a friendly symbolic link to it.
To delete the user, without removing the files in the user's home directory, run the following command:
$ sudo deluser username
If you want to delete the user's home directory along with the user account, issue the following command with the --remove-home
flag:
$ sudo deluser username --remove-home
If you had previously included the deleted user in the sudo group, you 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.
Conclusion
In this article, you have learned how to add and remove users on your Ubuntu 18.04 machine. You should now have a 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.
✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.