Add a Supplementary Group
Add a Supplementary Group
The assistant already belongs to some groups and now needs to join the school's report team too. The goal is to add one supplementary membership while preserving the others. A supplementary group is an additional group associated with the account, alongside its primary group.
usermod can update that list, but the options need careful reading. Replacing a list and appending to it are different operations. We will choose append explicitly, then discuss why an already-running shell may not immediately acquire the new group credentials.
What you’ll learn
- Append an account to a supplementary group.
- Avoid replacing other memberships and verify the change in a fresh session.
A new membership does not rewrite old processes
Existing groups
The assistant may already need other supplementary groups.
old groupsAppend
usermod -aG adds the selected group to the database list.
old groups + school-reportsFresh session
A new suitable session acquires the updated group credentials.
verify with id
Append school-reports to the assistant’s groups
Prepare the example
In the practice VM, both school-assistant and school-reports must already exist. Use the account and group creation lessons if they do not. Inspect the current memberships before changing them, and use an account authorized to administer users.
Bash · Linux terminal
sudo usermod -aG school-reports school-assistant
id school-assistantExpected behavior; machine-dependent details
The reports group appears in the account's configured memberships.usermod -aG school-reports school-assistant combines append, -a, with the supplementary-group list option, -G. Together they add the report group rather than replace the whole list with that one name. Omitting append can remove memberships you intended to retain.
id school-assistant inspects the account's configured identity and groups. That is not identical to running id inside an old assistant session: processes normally keep credentials acquired when they started. Use a suitable fresh login or session when checking the access the assistant actually receives after the change.
Append memberships and check a new session
Adding a user to a supplementary group is a common way to grant access to shared files, development tools or administrative functions.
Why do we need groups in Linux?
Groups are a way to organize users so that you can manage permissions more easily. For example, you might want several users to access the same folder or run certain commands — groups make that possible without assigning permissions individually.
Step 1: Check the current groups of a user
Before adding a user to a new group, it’s helpful to see which groups they already belong to.
groups username
Example:
groups alice
alice : alice sudo
This means the user alice is already in the alice and sudo groups.
Step 2: Add the user to a new group
To add a user to a group, we use the usermod command with the -aG options:
sudo usermod -aG groupname username
Let’s say we want to add alice to the developers group:
sudo usermod -aG developers alice
Important: The -a means append, and -G specifies the group list. Forgetting -a could remove the user from other groups!
Step 3: Re-check the user’s groups
Now let’s check if the user has been added successfully:
groups alice
alice : alice sudo developers
Step 4 (Optional): Verify with a new login
The group changes may not apply immediately for running sessions. Ask the user to log out and log back in, or you can use the newgrp command to switch groups in the current session:
newgrp developers
Add supplementary group membership without replacing existing groups
You’ve just added a user to a group in Linux! This is really useful when setting permissions on files, folders, and executing specific admin-level tasks.
Try it, then check the worked answer
Your task: Append a group while retaining others.
In the practice VM, both school-assistant and school-reports must already exist. Use the account and group creation lessons if they do not. Inspect the current memberships before changing them, and use an account authorized to administer users.
Bash · complete example for this question
sudo usermod -aG school-reports school-assistant
id school-assistantExpected behavior; machine-dependent details
The reports group appears in the account's configured memberships.Worked answer
usermod -aG school-reports school-assistant
Choose the append form, usermod -aG. The requirement includes retaining existing supplementary groups, so replacing the list does not satisfy it. Compare the membership record afterward, then check actual credentials in a new suitable session.
Check your decision
Check the important distinction
Append groups without replacing existing memberships
Adding a role should not accidentally remove another role. Use append when that is the intent, inspect both old and new memberships, and distinguish account database changes from credentials already held by running processes.
Reaching the recap and completing the quizzes are separate milestones.