Looking to manage user permissions and settings on your Ubuntu system? Look no further than this step-by-step tutorial on adding and removing users on Ubuntu 20.04 and Ubuntu 18.04! As a multi-user operating system, Ubuntu offers granular control over individual user accounts, with unique permissions and preferences for both command-line and GUI applications.
Learn the basics of user management on Linux, and ensure your Ubuntu system is secure and efficient for all users.
Prerequisites
In order to manage user accounts, it is necessary to have root access or be a user with sudo privileges.
There are two methods of creating new users:
- From the command line.
- Through the GUI.
Adding a User from the Command Line
You can utilize two command-line tools, namely useradd
and adduser
, to generate a fresh user account in Ubuntu.
useradd
is a utility that operates at a low level, while adduser
is a Perl script designed to serve as a user-friendly interactive interface for useradd
.
To create a new user account, you can use the adduser
command followed by the desired username. For instance, if you want to add a user with the username “username
“, simply run the adduser
command. This process is quick and straightforward:
sudo adduser username
Output:
Adding userusername' ...
Adding new group
username’ (1001) …
Adding new userusername' (1001) with group
username’ …
Creating home directory/home/username' ...
Copying files from
/etc/skel’ …
A set of questions will be presented to you, and you will be required to input and verify the new user password. Answering the remaining questions is not mandatory.
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]
To ensure the accuracy of the information, please enter ‘Y
‘ to confirm.
After executing the command, a home directory will be generated for the new user, and files from the /etc/skel
directory will be duplicated into the user’s home directory. The user will be able to create, modify, and remove files and directories within their home directory.
To grant the new user the ability to execute administrative tasks, it is necessary to add the user to the sudo group:
sudo usermod -aG sudo username
Adding a User through the GUI
In case you feel uneasy using the command line, an alternative method for creating a new user account involves utilizing the graphical user interface. To proceed with this approach, refer to the step-by-step instructions outlined below:
- To access the Users tab, you need to open the settings window and click on it.
- Once prompted, input your user password and click the Unlock button.
After inputting the password, the “Unlock” button will be replaced with a green “Add User” button.
- Upon clicking the “Add User” button, the Add User dialog box will be displayed:
- You have the option to choose between a standard or administrator user for the new user, and provide the necessary information. Afterward, simply click on the “Add” button to complete the process.
Removing a User from the Command Line
There are two ways to delete a user account in Ubuntu: using the command “userdel
” or its interactive front-end “deluser
“.
You can remove a user by using the deluser
command and specifying the username
as the parameter.
sudo deluser username
Executing the aforementioned command will leave the user files intact and not delete them.
To remove a user along with their home directory and mail spool, simply add the “--remove-home
” flag:
sudo deluser --remove-home username
Removing a User through the GUI
- To access the “Users” tab, you need to open the settings window first.
- To unlock, simply click on the designated “Unlock” button and provide your user password as prompted.
- If you want to delete a username, simply click on it, and a red button labeled “Remove User…” will appear in the bottom right corner.
- After clicking the “Remove User…” button, a prompt will appear asking whether to retain or delete the user’s home directory. Selecting either option will result in the removal of the user.
Conclusion
In this tutorial, we have demonstrated the process of adding and deleting users in both Ubuntu 18.04 and 20.04. These fundamental skills are essential for any Linux user to possess. If you have any queries, please feel free to drop a comment below.