How To Manage Users in Linux

Manage Users in Linux
(Image credit: Tom's Hardware)

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 a Ubuntu 20.04 install but you could run this how-to on a Raspberry Pi. Some of thia 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.

Jo Hinchliffe

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

  • ezst036
    Admin said:
    We’ll show you how to use both the GUI and the terminal to add and remove users to and from different user groups.

    Thank you so much for also including the GUI parts of the tutorial.

    There is a pernicious and rampant myth out there that everything in Linux requires users to do things in the terminal. In reality, all but a handful of wonky tasks require the command line.

    Command line usage isn't any more required in any OS, comparitively.(Windows cmd, Mac terminal, Linux terminal.) We left that phase at least a decade ago - yet the myth persists.
    Reply
  • CXB
    ezst036 said:
    Thank you so much for also including the GUI parts of the tutorial.

    There is a pernicious and rampant myth out there that everything in Linux requires users to do things in the terminal. In reality, all but a handful of wonky tasks require the command line.

    Command line usage isn't any more required in any OS, comparitively.(Windows cmd, Mac terminal, Linux terminal.) We left that phase at least a decade ago - yet the myth persists.


    If only.

    While it's true that the vast majority of everyday tasks in Linux can use the GUI interface, it only takes ONE exception to ruin that reputation.
    It's in the nature of Linux that some applications and drivers are supported by entities outside the main distributors: manufacturers, talented individuals, talented teams, all contributing their work FREE of charge. While this is a great strength (in numbers), the lack of a commercial relationship and it's underlying responsibilities for warranty etc, means that some manufacturers do not support their products fully in Linux.

    As an example, over the past year, I've had to:
    Find bluetooth drivers online that have had to be renamed (as a different driver to the one it's chip is supposed to represent) and posted to the correct driver directory. (The bluetooth works perfectly in Windows)
    Re-compile WLAN drivers (because the manufacturer didn't update them), from a generous Github individual. (The Wifi works perfectly in Windows)
    On a normal Secure Boot system, re-register the nVidia drivers(!) - that's now fixed. (My 3070 works perfectly in Windows)
    On a Raspberry Pi (yes, the most popular system ever manufactured), jump through a few hoops to get it to boot off a HDD or SDD (ok, not Pi4), eg replacing PARTUUIDs, modifying fstab etc. Part of the 'fun'! (Yes, I can boot from any storage device my motherboard recognises, in Windows). PS, I'm not a Windows fan! I dual-boot and mainly use Linux Mint - a great distribution.
    Having problems with an encrypted Home directory, that borked the Swap directory settings and impacted RESUME. I've reverted to the old 'safe' settings.These aren't 'wonky tasks'. They are tasks needed to maintain a modern system using common, commercial components.

    The fact is, that Linux changes quite a lot, over time. New ideas are introduced (systemd, snap etc) or expanded upon. Some distributions favour certain 'flavours' etc. This has a bearing on which directories are used for which purposes, and requires everyone to choose which structures they are going to deliver into. That requires a commitment to maintain software and drivers, that isn't always forthcoming. And I'm not talking about some old, obscure hardware or driver. Yes, Windows has had such problems too - going from 32-bit to 64-bit, for example, but it pretty well provides all maintenance tasks through a GUI, even regedit! Sure, Powershell is still needed by Systems Admins in commercial settings, but the 'normal single user' doesn't need to revert to it, EVER.

    I'd like to support your point about providing GUI instructions. It's very important, and much needed.
    A GUI system enforces task orientation, delivering what is needed to accomplish the task, irrespective of the underlying structure.
    A terminal system involves knowledge of the underlying structure and their connectivity. It has about as much relevance to 'the normal user' as a car wiring diagram....

    Regards.
    Reply
  • ezst036
    CXB said:
    While it's true that the vast majority of everyday tasks in Linux can use the GUI interface, it only takes ONE exception to ruin that reputation.

    It's in the nature of Linux that some applications and drivers are supported by entities outside the main distributors: manufacturers, talented individuals, talented teams, all contributing their work FREE of charge. While this is a great strength (in numbers), the lack of a commercial relationship and it's underlying responsibilities for warranty etc, means that some manufacturers do not support their products fully in Linux.

    I agree with some of this - and the obvious example (call it a reverse example if you prefer) is the Steam Deck. I've seen on numerous sites that when using Windows, the Deck just doesn't feel right.(Some things didn't work at all. Valve has issued driver updates, but still)

    But I don't think anybody would dare say that Windows is full of problems, this that and the other thing, just because Valve has specifically chosen not to properly support Windows. The issue is Valve. And the troubleshooting to get it working, yes, that's wonky.

    The same thing goes for, as you mentioned later, bluetooth drivers. Is that really a Linux problem? Or is that a vendor problem?

    CXB said:
    As an example, over the past year, I've had to:
    Find bluetooth drivers online that have had to be renamed (as a different driver to the one it's chip is supposed to represent) and posted to the correct driver directory. (The bluetooth works perfectly in Windows)
    Re-compile WLAN drivers (because the manufacturer didn't update them), from a generous Github individual. (The Wifi works perfectly in Windows)
    On a normal Secure Boot system, re-register the nVidia drivers(!) - that's now fixed. (My 3070 works perfectly in Windows)
    On a Raspberry Pi (yes, the most popular system ever manufactured), jump through a few hoops to get it to boot off a HDD or SDD (ok, not Pi4), eg replacing PARTUUIDs, modifying fstab etc. Part of the 'fun'! (Yes, I can boot from any storage device my motherboard recognises, in Windows). PS, I'm not a Windows fan! I dual-boot and mainly use Linux Mint - a great distribution.
    Having problems with an encrypted Home directory, that borked the Swap directory settings and impacted RESUME. I've reverted to the old 'safe' settings.These aren't 'wonky tasks'.

    These are definitely wonky tasks, as are editing the registry, issuing PING commands in the MS CMD terminal, and tracking down various missing DLLs needed in some SYS directory or other. Anything at all with Raspberry Pi in the same sentence is by definition wonky. Grandma doesn't do this stuff. And if you do happen to have a Grandma that's going around setting up AIs with RPIs, wow are you lucky! :-)

    CXB said:
    On a normal Secure Boot system, re-register the nVidia drivers(!) - that's now fixed. (My 3070 works perfectly in Windows)

    Again, Steam Deck with Windows. Nvidia chooses to make life difficult for Linux Users and recently (finally) open sourced a large portion of it's driver stack in order to address issues, yes wonky issues, such as this.

    Ask any Linux user with an onboard Intel HD or AMD video card. They don't have these issues. That's because they're not a Linux issue. This is an Nvidia issue. I probably cannot say that strongly enough, really. This is an Nvidia issue. There's not one person in the Linux world who could, ever, fix this. Linus Torvalds couldn't fix it. The entire Red Hat Corporation - who actually pays developers to work on graphics and related directly to Nvidia - couldn't fix this. It required the Nvidia Corporation to get up off of its couch and fix the problem. They were guarding all of the doors and they were holding all of the keys. And it will still take some time from this moment for the new driver to go through its maturation issues. And whatever Terminal nonsense had to be pursued on your end because of Nvidia's issue, was ultimately unnecessary and due to Nvidia.

    Ask any Linux user with an onboard Intel HD or AMD video card. They don't have these issues. Or on the rare occasion that it does happen, a bug ticket can be put in and get it fixed so that whatever terminal headaches can peacefully go away.

    CXB said:
    The fact is, that Linux changes quite a lot, over time. New ideas are introduced (systemd, snap etc) or expanded upon. Some distributions favour certain 'flavours' etc. This has a bearing on which directories are used for which purposes, and requires everyone to choose which structures they are going to deliver into. That requires a commitment to maintain software and drivers, that isn't always forthcoming. And I'm not talking about some old, obscure hardware or driver. Yes, Windows has had such problems too - going from 32-bit to 64-bit, for example, but it pretty well provides all maintenance tasks through a GUI, even regedit! Sure, Powershell is still needed by Systems Admins in commercial settings, but the 'normal single user' doesn't need to revert to it, EVER.

    Maybe the mistake I made was in using the word 'wonky', but mostly what you're describing are wonky administrative tasks. What I meant was precisely this.

    The average user does not need to put on an administrative hat like they would've had to do a decade ago or so in Linux. Everything "just works."

    The challenge that Linux users have had (which is much easier these days) has been to assemble a known - basically Steam Deck - computer. Get an AMD video card so that the drivers are generally unquestionable, get a motherboard with Intel this and that so that all of the other components are using Intel's driver sets. They put a lot of time into ensuring driver quality. The Wifi is a key issue point because of how prevalent Broadcomm hardware is and how stuck up Broadcomm is about its absolute refusal to issue decent Linux support. Broadcomm is the same way as described earlier. They are guarding all of the doors and they are holding all of the keys. So Linux users when they can do so get either Qualcomm wifi, Intel wifi, or there are a few others. Who is your Bluetooth chip manufacturer?(if I may ask)

    But all of this avoids the point. And as a Linux Mint user you should know this. Everything you want to do in Mint is all easy, and it's all GUI driven. When you wanted to install Blender or some word processor, it was GUI driven. When you wanted to launch your web browser, what did you do? You clicked on the "start" menu with your mouse and there it was. Click. Mouse. Open. There's no terminal requirement anymore. Even when they release Mint version 22, you can upgrade the whole ---entire--- operating system with one single button click. I know its only one mouse click. Because I've done it myself.


    The system snapshots are GUI driven. Securing the repositories is GUI driven. That's how mature the Linux environment is these days. None of it requires the terminal. These are more of the "daily tasks" that a user might run into.

    CXB said:
    While it's true that the vast majority of everyday tasks in Linux can use the GUI interface, it only takes ONE exception to ruin that reputation.

    Systems troubleshooting are not the exception. Windows has powershell and regedit just the same when issues pop out. Yes, I've had my fair share of broken drivers pulled off of driverguide that needed some sort of "help".(usually, it was DLLs or an INI file) Now maybe you can laud regedit for being UI driven, but go ahead and ask 5 people to describe what an HKEY_CLASSES_ROOT is, and see what answers arrive.
    Reply