Courseiva
LFCSChapter 6 of 16Objective 3.1

User Account and Group Management

How do you let the right people into a Linux system while keeping everyone else out? The answer is user accounts and groups — the fundamental building blocks of Linux security. If you are studying for the LFCS exam, mastering how to create, modify, and delete users and groups is non-negotiable: virtually every real-world server task starts with getting these basics right.

12 min read
Beginner
Updated Jul 23, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture User Account and Group Management

The Apartment Building Key System Analogy

A building manager’s master key ring is the central authority for every lock in the apartment block.

Each apartment has a unique key that opens only that specific flat’s door. That key is like a user account: it belongs to one person, and it grants access only to that person’s resources. The building also has a “staff” key that opens the laundry room, the gym, and the storage closet — but not any tenant’s apartment. That staff key is a group: it gives a set of permissions to multiple people who need the same access. The manager keeps a log of who holds which key, and when a tenant moves out, the manager cancels that key and issues a new one to the incoming tenant.

Now imagine the building has a “cleaning crew” key that opens every door except the penthouse safe. One cleaner leaves the job, so the manager just deletes that person from the crew list. The crew key itself stays the same; the departing cleaner’s copy stops working when the manager removes them from the group. This exactly mirrors Linux user and group management: the system (the manager) creates user accounts (individual keys), assigns them to groups (key types), and can delete or modify those accounts without changing the group’s permissions. When you create a user in Linux, you are issuing a unique key. When you add that user to a group, you are giving them a copy of the group key. And when you delete the user, you are taking back every key they ever held.

How It Actually Works

A Linux system is a multi-user environment, meaning many people can log into the same machine at the same time, each seeing their own files and running their own processes. To manage all these people securely, Linux uses user accounts and groups. Every person (or service process) that interacts with the system must have a user account. That account is identified by a username (the human-readable name) and a user ID (UID), which is a number the system uses internally. Linux does not care about the username — it cares about the UID.

When you install a fresh Linux system, it automatically creates a special user called root. The root user has UID 0 and is all-powerful: it can read, write, or delete any file, install or remove any software, and change any system setting. Because root is so powerful, you never use it for everyday tasks. One careless command as root can destroy the entire operating system. Instead, you create ordinary user accounts for daily work and use a tool like sudo to temporarily borrow root power when you need it.

A user account contains several pieces of information stored in the file /etc/passwd. This file lists one line per user, with fields separated by colons. Each line includes the username, a placeholder for the password (the actual password is stored, encrypted, in /etc/shadow), the UID, the primary group ID (GID), the user’s full name (often called the GECOS field), the path to the user’s home directory (usually /home/username), and the user’s default shell (the program that runs when they log in, typically /bin/bash).

Groups are collections of user accounts. A group has a name and a group ID (GID), stored in /etc/group. Every user has a primary group, which is the group that owns any new files the user creates. A user can also belong to supplementary groups, which grant additional permissions. For example, if a file’s permissions allow only members of the “developers” group to edit it, you simply add a user to that group, and they instantly gain the ability to edit that file. This is far easier than changing the file’s permissions for each individual user.

To create a user, you use the command useradd. The simplest form is: - sudo useradd jane

This creates a user “jane” with a UID assigned automatically (usually the next available number, starting from 1000), a primary group also called “jane”, and a home directory /home/jane. If you want more control, you can specify: - sudo useradd -m -u 1050 -g developers -G admin,www-data -s /bin/bash jane

The -m flag creates the home directory if it doesn’t exist. -u sets a specific UID. -g sets the primary group. -G adds supplementary groups. -s sets the shell.

To modify an existing user, you use usermod. For example, to change Jane’s primary group: - sudo usermod -g engineers jane

To add her to a supplementary group without removing her existing ones: - sudo usermod -aG docker jane

The -a flag is crucial: it means “append”. Without it, -G replaces all current supplementary groups with the one you specify — a common trap.

To delete a user, you use userdel. The basic command: - sudo userdel jane

This removes the user from /etc/passwd and /etc/shadow but leaves the home directory and mail spool intact. To also remove the home directory: - sudo userdel -r jane

Be careful: you cannot delete a user while they are logged in or while any process they own is running.

Group management mirrors user management: - groupadd developers — creates a new group. - groupmod -n newname developers — renames the group. - groupdel developers — deletes the group. You cannot delete a group if it is any user’s primary group.

Every piece of information about users and groups is stored in plain text files. You can even edit these files directly using a text editor, though it is safer to use the dedicated commands. The relevant files are: - /etc/passwd — user account information (but not passwords). - /etc/shadow — encrypted passwords and password expiry data. Only root can read this file. - /etc/group — group definitions. - /etc/gshadow — group passwords and group administrator information.

Permissions in Linux are based on three entities: the file’s owner (a user), the file’s group (a group), and everyone else (others). Each entity can have read (r), write (w), and execute (x) permissions. When you create a user and put them in the right groups, you are building the entire access control structure of the system. Without users and groups, every user would be anonymous or, worse, would have to share the root account — which is a catastrophic security risk.

This diagram shows how a user account connects to its UID, primary group, supplementary groups, home directory, and shell, and how group membership controls file system permissions.

Walk-Through

1

Plan your user and group structure

Before running any commands, decide how you will organise users into groups based on their roles (e.g., developers, admins, support). This avoids creating random groups later. Write down which groups need access to which directories.

2

Create the groups

Use 'sudo groupadd groupname' to create each group. Verify with 'cat /etc/group' or 'getent group'. Ensure you do not accidentally create a group with the same name as an existing user (though it is allowed, it can cause confusion).

3

Create user accounts with appropriate flags

Use 'sudo useradd -m -G group1,group2 -s /bin/bash username'. The -m flag creates the home directory. The -G flag adds the user to supplementary groups. If you want a specific UID, add -u UID. If you want a specific primary group, add -g groupname.

4

Set the user’s password and force a change on first login

Run 'sudo passwd username' to set an initial password. Then run 'sudo chage -d 0 username' to force the user to change that password the first time they log in. This is a security best practise for new accounts.

5

Set directory permissions and ownership

Change the group owner of important directories with 'sudo chown root:groupname /path/to/dir'. Set permissions with 'sudo chmod 770 /path/to/dir' (or 750 for read-only group access). Verify with 'ls -ld /path/to/dir'.

6

Test the setup by logging in as the new user

Switch to the new user with 'sudo su - username' (or use ssh). Check that they can create files in the appropriate directories. Use 'id' to confirm group membership. If something is wrong, run usermod to adjust groups or chmod to adjust permissions.

7

Plan for offboarding

When a user leaves, first kill their processes with 'sudo pkill -u username'. Optionally lock the account with 'usermod -L username' before deleting, to ensure no accidental access. Then run 'sudo userdel -r username' to remove the account and home directory. Find and reassign any remaining files owned by that user.

What This Looks Like on the Job

Imagine you work at a medium-sized web development company called Pixelflame. The company has 40 employees, including developers, system administrators, and customer support staff. All of them need access to a shared Linux server that hosts the company’s applications and client data.

Your job as the junior sysadmin is to set up user accounts for all new hires and remove accounts when people leave. You also need to organise access: developers should be able to read and write the source code folders, system administrators need root-level access for server maintenance, and customer support staff should only read certain log files to assist clients.

Here is how you would actually tackle this on a real server:

First, you create three groups: developers, sysadmins, and support. You use: - sudo groupadd developers - sudo groupadd sysadmins - sudo groupadd support

Next, you create the directories where the teams will work (if they don’t already exist): - sudo mkdir /srv/projects /var/log/app /opt/tools

You set the group owner of each directory and adjust the permissions so only members of the appropriate group can access them: - sudo chown root:developers /srv/projects - sudo chown root:sysadmins /opt/tools - sudo chown root:support /var/log/app

Then you set permissions so the group can write to their directory, but others have no access: - sudo chmod 770 /srv/projects (owner and group have full access, others get none) - sudo chmod 770 /opt/tools - sudo chmod 750 /var/log/app (owner and group can read/execute, group can also write, others nothing)

Now a new developer named Alex joins. You create their account: - sudo useradd -m -G developers -s /bin/bash alex

The -G developers flag adds Alex to the supplementary developers group. Because the /srv/projects directory has group ownership set to developers, Alex immediately has full read, write, and execute access to that folder. You don’t need to change any permissions for Alex individually.

Later, the helpdesk support person Rachel needs temporary access to the log files for a client issue. Instead of creating a whole new group or modifying file permissions, you simply add Rachel to the support supplementary group: - sudo usermod -aG support rachel

Rachel can now read /var/log/app without any other changes. This is the power of groups: one command grants access to every resource the group controls.

When a sysadmin named Ben leaves the company, you need to lock him out immediately. You run: - sudo userdel -r ben

This removes Ben’s account and his home directory. But what if Ben had files scattered across the server? His old files will now show a numerical UID instead of a username because the account no longer exists. You should run a find command to locate those files and reassign them to another user: - sudo find / -user ben -exec chown newadmin {} + 2>/dev/null

In real companies, you rarely work alone. You might use a configuration management tool like Ansible or Puppet to create users across hundreds of servers at once. But the underlying commands are the same — useradd, usermod, userdel, groupadd, groupmod, and groupdel — and the LFCS exam expects you to know them cold.

How LFCS Actually Tests This

The LFCS exam objective 3.1 is titled “Create, modify, and delete user accounts and groups.” The exam tests both your knowledge of the commands and your ability to read and edit the system files that store user and group information. You will not have internet access during the exam, so you must memorise the command flags and the structure of /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow.

Here are the exact concepts the exam loves to test:

The difference between useradd and adduser. useradd is the low-level Linux command; adduser is a Perl script that exists on some distributions (like Debian/Ubuntu) and calls useradd behind the scenes. The exam uses useradd.

The -r flag on userdel: does it remove the home directory? Yes. But what about the mail spool? By default, userdel removes the mail spool file (usually /var/mail/username) when you use -r. Some versions also require -f to force removal if the user is still logged in.

The -a (append) flag on usermod: this is the number one trap. If you run “usermod -G group1,group2 username” without -a, you replace the user’s current supplementary groups with only group1 and group2. To add groups without losing existing ones, you must use “usermod -aG group1,group2 username”.

The password file /etc/passwd: the format is “username:password:UID:GID:GECOS:home_dir:shell”. The password field today always contains an ‘x’ because actual passwords are in /etc/shadow.

UID ranges: root is 0. System users typically have UIDs 1-999 (or 1-499 on older systems). Regular users have UIDs 1000+ (or 500+ on older systems). You are expected to know this for questions about user creation defaults.

Primary group vs supplementary group: Every user has exactly one primary group. Files they create have the primary group as the file’s group. Supplementary groups are extra groups the user belongs to, granting additional permissions.

Deleting a group: You cannot delete a group if it is the primary group of any existing user. The command “groupdel developers” will fail with an error message if any user has developers as their primary group. You must change those users’ primary groups first.

The /etc/skel directory: When you create a user with useradd -m, the system copies all files from /etc/skel into the new user’s home directory. You can check and customise /etc/skel to control the default environment for new users.

Forcing password change on first login: You can do this with “sudo passwd -e username” or by setting the password expiry fields in /etc/shadow. The exam may ask you to set a password that expires immediately.

Locking and unlocking accounts: “usermod -L username” locks the account by putting a ‘!’ in front of the encrypted password in /etc/shadow. “usermod -U username” unlocks it.

The -c flag on useradd and usermod: this sets the GECOS field (the user’s full name). For example: “sudo useradd -c 'Jane Doe' jane”.

The -d flag on useradd and usermod: this sets the user’s home directory path. For usermod, you need to manually move the home directory’s contents or use the -m flag to move them automatically.

The -s flag on useradd and usermod: sets the user’s login shell. Common shells are /bin/bash, /bin/sh, /bin/zsh. If you set it to /sbin/nologin or /usr/sbin/nologin, the user cannot log in interactively.

The exam will present you with a scenario and ask: “Which command achieves this result?” The answer is always one of the six core commands, often with a specific combination of flags. If the question says “add group membership without removing existing groups”, the answer MUST include -aG.

Another common trap: the exam asks about creating a user with a specific UID and home directory. You must use the -u, -m, and -d flags correctly. If you forget -m, the home directory won’t be created.

You may be asked to edit /etc/group directly using vipw or vigr (which lock the file to prevent concurrent edits) instead of using the commands. Know that vipw edits /etc/passwd and vigr edits /etc/group. These are safe editing tools that validate syntax.

The exam also tests password ageing: chage command. Know how to set expiry dates, minimum days between changes, maximum days, and warning days. Questions about forcing a password change on next login use “chage -d 0 username” (sets last password change date to epoch, forcing change on next login).

Key Takeaways

Every Linux user has a unique UID (user ID number) and belongs to exactly one primary group and zero or more supplementary groups.

Use 'sudo useradd -m username' to create a user with a home directory; omit -m and no home directory is created.

The -a (append) flag on usermod is non-negotiable: without it, -G replaces all existing supplementary groups instead of adding to them.

The /etc/passwd file stores user account info but not passwords; actual encrypted passwords live in /etc/shadow, which only root can read.

You cannot delete a group if it is any user's primary group; change those users' primary groups first with 'usermod -g newgroup username'.

The /etc/skel directory is the template for new user home directories; customise it to give every new user the same default files.

Lock a user account with 'usermod -L username' and unlock it with 'usermod -U username' without deleting any data.

The 'chage -d 0 username' command forces the user to change their password on their next login.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Primary Group

Every user has exactly one primary group.

Files created by the user inherit the primary group as the file's group.

Cannot be removed from a user without setting a new primary group first.

Supplementary Group

A user can belong to zero or more supplementary groups.

Supplementary groups grant additional permissions but do not change the group of newly created files.

Can be added or removed freely using 'usermod -aG' or 'usermod -G' (with care).

useradd

Creates a new user account from scratch.

Requires -m to create home directory.

Sets initial UID, GID, shell, and home directory.

usermod

Modifies an existing user account.

Can change UID, shell, groups, home directory, and more.

Does not create a new user; the user must already exist.

/etc/passwd

Contains username, UID, GID, GECOS, home directory, and shell.

World-readable (any user can see this file).

The password field contains 'x' to indicate an external shadow file.

/etc/shadow

Contains encrypted password, password expiry data, and account lockout info.

Only root and users in the shadow group can read it.

Stores password hashes using algorithm identifiers like $6$ (SHA-512).

userdel

Completely removes the user account from /etc/passwd and /etc/shadow.

Can optionally remove the home directory and mail spool with -r.

Irreversible once executed (unless you recreate the account manually).

usermod -L

Locks the account by placing a '!' in the password field in /etc/shadow.

Leaves the user account and all files intact.

Fully reversible with 'usermod -U'.

groupadd

Creates a new group entry in /etc/group.

Assigns the next available GID or a specified GID.

Does not affect any existing users or files.

groupdel

Removes a group entry from /etc/group.

Fails if the group is any user's primary group.

Files owned by the deleted group show the GID number instead of the group name.

Watch Out for These

Mistake

You can delete a user while they are logged in by using 'userdel -f'.

Correct

The -f flag forces removal of files owned by the user, but it does not kill their running processes. The user remains logged in until they log out. Best practise is to kill their processes first with 'pkill -u username' then delete the account.

Beginners hear 'force' and assume it overrides everything. In reality, 'force' only affects file removal, not active sessions.

Mistake

A user's primary group and username are always the same.

Correct

By default, many distributions create a group with the same name as the user, but this is configurable. You can create a user with a different primary group using 'useradd -g existinggroup username'. The user and group names are independent.

This misconception comes from seeing the default behaviour on Ubuntu or similar distros and assuming it is universal. It is not guaranteed.

Mistake

Adding a user to a group automatically gives them access to all files owned by that group.

Correct

It only gives them the permissions that the group has on specific files and directories. If a directory is owned by group 'developers' but the permissions are 750 (owner read/write/execute, group read/execute, others nothing), then group members can read and execute but not write. You still must set file permissions to grant the access level you intend.

People conflate group membership with full access. They forget that group permissions are separate from ownership and must be explicitly set.

Mistake

The GECOS field in /etc/passwd is a mandatory field for user accounts.

Correct

The GECOS field is optional and used only for storing the user's full name and contact info. It has no effect on system operations. You can leave it blank.

The name 'GECOS' sounds official and mandatory, but the field is purely for the administrator's convenience.

Mistake

Deleting a group with 'groupdel' automatically removes the group's permissions from all files.

Correct

Deleting a group only removes the group definition from /etc/group. Files that had that group as their group owner will now show a numerical GID instead of a group name. The permissions are still in place but the group name disappears.

Beginners think 'delete' means undo everything. In Linux, deleting the account or group doesn't retroactively change files' metadata.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between useradd and adduser?

useradd is the low-level binary command available on all Linux systems. adduser is a Perl script that exists on Debian-based distributions and calls useradd interactively, prompting for the full name, password, and other details. The LFCS exam tests useradd.

Can I have two users with the same UID?

Technically yes, but it is a terrible idea. UIDs must be unique for proper file ownership tracking. If two users share the same UID, the system treats them as the same user for file access. Always assign unique UIDs.

What happens to a user’s files when I delete the user with userdel?

By default, the files remain on disk but their owner field in the file system shows the old numerical UID. If you use 'userdel -r', the home directory and mail spool are removed, but files outside the home directory remain orphaned.

How do I add a user to multiple groups at once?

Use 'sudo usermod -aG group1,group2,group3 username'. The groups are comma-separated with no spaces. The -a flag is mandatory to keep existing supplementary groups.

What does 'chage -d 0' do exactly?

It sets the user’s last password change date to the Unix epoch (January 1, 1970). Because this is in the past, the password is considered expired and the user will be forced to change it on their next login.

Why can’t I delete a group even though no users are members?

The group might be set as the primary group for some users. Run 'getent passwd | grep :groupname:' to see which users have it as their primary group. You must change those users' primary groups first before deleting the group.

Terms Worth Knowing

Keep going

You've finished User Account and Group Management. Continue through the LFCS study guide to build a complete picture of the exam.

Done with this chapter?