About this post
It doesn't matter if you're a desktop user or your web server is running on Linux; one of the important things is knowing how to add, edit, or even delete users on the Linux operating system.
In this post, we will learn about Linux users and how to manage them.
note
I'm an Ubuntu user and the OS version is 24.04.1 LTS. You may find it a bit different in GUI if you're on another version but the overall steps should fit you.
Table of Contents
Users on Linux
Just like in real life, a user has a unique identity that can have their characteristics. Besides, as a person can have some specific roles in their society, users can exist for a particular purpose. Almost all computer-related fields have this term and refer to that as a "user account".
So we can think of Linux as a small society like a library, where there are people (user accounts) doing different things. New people can sign up for a library account, or they can cancel their subscription, being banned, and things like this.
List of Users
‑ List Users in Terminal
To see a list of users, you can run the following command in the terminal:
cat /etc/passwd # or getent passwd
Note that in the result of above commands, you will see other users, these are linux system users that are created automatically during installation and they are existed for specific os level tasks, so ignore them with peace of mind.
If you just want to see human users (users added by you), you can run the following command:
cut -d: -f1,3 /etc/passwd | egrep ':[0-9]{4}$' | cut -d: -f1
For me, this is the result:
hosein
The above command is from a question on ask ubuntu questions list. See the original here if you want.
‑ List Users in GUI
To see users on the graphical interface on Ubuntu, you can follow these steps:
- Open settings
- From the sidebar, click on the "system" tab
- Then click on users
The result will be something like the above image, the current user is Hosein
and there is no other user on this machine, we'll add another user in the next section.
Note that you need to "Unlock" advanced settings using your root password to make it possible to apply changes to the users.
Add a User
‑ Add a User in Terminal
To add a user in the terminal, after opening that, run sudo adduser USERNAME
and add your desired username instead of USERNAME
, for example, sudo adduser guest
. After running this command, you'll be asked for (on Ubuntu 24):
- Password, and password repeat.
- Full name for the user (optional).
- Room number (optional).
- Work phone (optional).
- Home phone (optional).
- Other data (optional).
After the above questions, you'll be asked to confirm the entered information, Press enter and then the user will be added. You can check the added user in the terminal by listing users with the help of commands from the previous section. I've added a new user named guest and this is the terminal result for listing:
hosein guest
‑ Add a User in GUI
To add a user in the graphical interface, follow these steps:
- Open settings and head over to the system tab, then click on users.
- Then you need to unlock the advanced settings. Click on the "Unlock..." button and enter your password.
- After that, click on the "Add User..." button. A new window will pop up and you should enter required information for the user. If you properly enter the values, the add button should be enabled.
- By clicking the add button, the new user will be added.
Edit a User
note
To edit a user successfully, you need to make sure that the named user isn't executing any processes.
‑ Edit a User in Terminal
To modify a user in the terminal, you can use the usermod
command. Check out the full details of this command in the terminal using man usermod
. We'll check some important and useful flags of this command.
- Using the
-p
flag, you can set a new password for the user. However, it is recommended to avoid this option in the command line because the password will be visible to users listing the processes.
sudo usermod -p PASSWORD USERNAME
- Using the
-e
, you can set an expiration date for the user account. By reaching the entered date, the user account will be inactive. You need to specify the date in YYYY-MM-DD format.
sudo usermod -e YYYY-MM-DD
‑ Edit a User in GUI
To edit a user in GUI:
- Open settings and head over to the system tab, then click on users.
- Then you need to unlock the advanced settings. Click on the "Unlock..." button and enter your password.
- If the user that you want to modify, isn't the current account, just select that from bottom.
- In the opened screen, you'll be able to change the name of the user, change the password, make the user administrator, or set the user language.
For the guest user, I've changed the profile image.
Please be aware that if you make a user an administrator, you permit the user to act just like you, so the administrator user will be able to edit users or do other sensitive actions.
Delete a User
cuation
You cannot undo the deletion action. So please try the steps of this section with a temporary user if you are reading this article for learning purposes! Also, it is a good practice to use the --backup
flag if you are going to remove an actual user.
‑ Delete a User in Terminal
To remove a user in the terminal you need to run the following command with administrator privileges. So, this is the command:
sudo deluser --remove-home USERNAME
Replace the user you want to delete in the above command, the --remove-home
flag will remove the home page of the user as well. Also, you can use the --remove-all-files
flag to remove files related to this user. Read all options of deletion using man deluser
. Please keep in mind that this action can be a dangerous one.
‑ Delete a User in GUI
To remove a user in GUI:
- Open settings and head over to the system tab, then click on users.
- Then you need to unlock the advanced settings. Click on the "Unlock..." button and enter your password.
- Select the user that you want to remove.
- In the opened screen, click on "Remove User".
- The pop up will ask for your confirmation. Also if you want to remove the user completely, you can check the option to "Delete Files and Settings".
Conclusion
Thanks for following through. At this point, you should be able to confidently create, edit, and remove users both in the terminal and graphical interface. To learn more about each command, you can always use the man COMMAND
and read the manual.