How To Manage Linux Users via the GUI and Terminal

User management with Linux
(Image credit: Pexels / OpenClipArt)

User management may not sound like the most glamorous task, but nonetheless it is an essential part of a busy system administrator's job. Creating new users, be they your family, friends or co-workers involves giving them the correct permissions, and managing what they can do. All of this can be done via the GUI and the terminal and in this how to we will show how.

(Image credit: Tom's Hardware)

All the commands in this how-to will work on most Linux machines. We’ve used an Ubuntu LTS install but you could run this how-to on a Raspberry Pi.
Some of this how-to is performed via the terminal. You can open a terminal window on most Linux machines by pressing ctrl, alt and t. When working through this how-to take extra care when you have multiple users set up that you are selecting and deleting the correct user accounts!

Add A New Linux User Via the GUI

(Image credit: Tom's Hardware)

For most, user management via the desktop is more than sufficient and thankfully most Linux distros have this down to a tee.

To add a user via the GUI

1. Open the settings application, scroll down the list and select the users tab.

(Image credit: Tom's Hardware)

2. Click on the unlock button and enter your password. Editing these settings requires us to unlock them via a password. This helps to avoid accidents when working with user accounts.

3. Click the Add User button to open a new dialog box.

(Image credit: Tom's Hardware)

4. Add the new user's name. The tool will suggest a username, but you are free to change this. You can either add a password for that user at this stage or you can allow the user to set their own password when they first log in. When done, click Add to save. You will be prompted for your password to confirm the creation of this user.

(Image credit: Tom's Hardware)

5. Optional step: Give users additional privileges by clicking the administrator tab as you create the new user, or by toggling the administrator button if the user account is already created.

(Image credit: Tom's Hardware)

6. Log off and switch users to the new user account. You should notice that they have their own Home directory and that any applications will use the configuration settings for that user.

Deleting a Linux User Via the GUI

(Image credit: Tom's Hardware)

Making sure that user accounts are deleted is good housekeeping. It removes unnecessary files, and more importantly it removes their access.

Using the same GUI application we can delete the user Zainab from our test installation.

1. Open the settings application, scroll down the list and select the users tab.

(Image credit: Tom's Hardware)

2. Click on the unlock button and enter your password. Editing these settings requires us to unlock them via a password. This helps to avoid accidental user deletions from your system.

3. Select the user account you wish to remove and click the Remove user button. Note that if that user is currently logged in you will get a warning that deleting a user whilst logged in may create issues.

(Image credit: Tom's Hardware)

4. Click Delete Files b to remove the user's Home directory. If you haven’t yet backed up the files, click on Keep Files.

(Image credit: Tom's Hardware)

Adding a User Via the Linux Terminal

(Image credit: Tom's Hardware)

The GUI is great but sometimes we need to get our hands dirty in the terminal and from here we can easily manage users. An aspiring system administrator and a Bash script can even automate the process. Adding a user to the system using the command line interface within a terminal is straightforward.

(Image credit: Tom's Hardware)

In the following example we have used sudo at the beginning of commands as they require root or sudo privileges in order to run. If you are logged in as root you don’t need to add sudo to these commands.

1. Add a new user using the adduser command. When prompted enter your password to confirm that you have sudo privileges. The new username must be lowercase.

2. Create a password and user details for the new user account. You don’t need to complete every piece of information.You can leave them empty by pressing the Enter key to skip them.

3. Confirm the new user information by typing y and then press Enter. Should there be an error you can type n to cancel the operation.

sudo adduser jamal

Adding a User to A Group via the Linux Terminal

Group memberships are used to ensure that multiple users in a group have basic permissions and privileges. Using groups we can ensure that users in a group have these basic permissions without the need to individually assign permissions to them.

1. Open a terminal.

2. Add the new user to the sudo group using the usermod command. The usermod command has two arguments. The first is -a and this appends the user. The G argument requires the name of the group(s) to which the user should be added.

sudo usermod -aG sudo <username>

Deleting a User Via the Linux Terminal

(Image credit: Tom's Hardware)

Deleting a user account using the command line interface is straightforward. Similar to previous adding a user example, we need to use sudo or be logged in as root to perform these operations.

1. Use the deluser command with the –remove-home argument to remove a user and their home directory. Similar to adding a user with adduser we can use deluser to remove user accounts. Adding the --remove-home arguments removes the user's home directory and deletes all of their files.

sudo deluser –remove-home <username>

(Image credit: Tom's Hardware)

2. Use deluser to delete a user without deleting their home directory. Occasionally we may need to remove a user without deleting their home directory and files. To do this you simply run the deluser command without any arguments added.

sudo deluser <username>

Between the GUI tools and the command line interface you now have a good collection of basic approaches to manage user accounts, their file contents and group access on most Linux systems.

TOPICS

Jo Hinchliffe is a UK-based freelance writer for Tom's Hardware US. His writing is focused on tutorials for the Linux command line.  

With contributions from