> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Managing Groups

> Managing Linux user groups and accounts—creating, renaming, assigning primary and supplementary groups, changing GIDs, deleting groups, and validating entries in /etc/group

In this lesson you'll learn how to create, modify, and delete groups, assign users to them, and verify the resulting entries in `/etc/group`. Managing groups simplifies permission control and is essential for multi-user Linux systems and team-based workflows.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/9E2T0ocsNwD7Od8i/images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/User-Management/Demo-Managing-Groups/demo-managing-groups-icon-slide.jpg?fit=max&auto=format&n=9E2T0ocsNwD7Od8i&q=85&s=293c947c4476de89b737c46922008223" alt="A dark presentation slide titled &#x22;Demo: Managing Groups&#x22; on the left with a blue line-icon of three connected people on the right. The design is minimalist with a navy background." width="1920" height="1080" data-path="images/Prep-Course-Red-Hat-Certified-System-Administrator-RHCSA/User-Management/Demo-Managing-Groups/demo-managing-groups-icon-slide.jpg" />
</Frame>

## Quick overview — what you'll do

1. Create system groups.
2. Create user accounts.
3. Assign users to supplementary groups and change primary groups.
4. Rename groups and change GIDs.
5. Remove groups and validate `/etc/group`.

## 1) Create groups

Create the groups you need with `groupadd`:

```bash theme={null}
# Create the Developers group
sudo groupadd developers

# Create the admins group
sudo groupadd admins
```

Verify the new groups by inspecting `/etc/group` or using `grep`:

```bash theme={null}
# Show the newly created groups (example)
$ grep -E 'developers|admins' /etc/group
developers:x:1007:
admins:x:1008:
```

## 2) Create users

Create three example users and their home directories with `-m`:

```bash theme={null}
sudo useradd -m groupuser1
sudo useradd -m groupuser2
sudo useradd -m groupuser3
```

Note: By default each user gets a private primary group that matches the username (for example, `groupuser1`).

## 3) Assign supplementary groups

Use `usermod -G` to set supplementary groups for an account. Important: the uppercase `-G` replaces the entire supplementary-group list; to append instead of replacing, use `-aG`.

<Callout icon="lightbulb" color="#1CB2FE">
  Use `-G` to set supplementary groups (this replaces the list). Use `-aG` to append to the existing supplementary groups without removing any existing ones.
</Callout>

Example — set `developers` and `admins` as supplementary groups for `groupuser1`, then append the `wheel` group:

```bash theme={null}
# Replace supplementary groups with developers and admins
root@control:/home# usermod -G developers,admins groupuser1

# Verify memberships
root@control:/home# id groupuser1
uid=1001(groupuser1) gid=1001(groupuser1) groups=1001(groupuser1),1007(developers),1008(admins)

# Append wheel without removing existing groups
root@control:/home# usermod -aG wheel groupuser1

# Verify memberships after append
root@control:/home# id groupuser1
uid=1001(groupuser1) gid=1001(groupuser1) groups=1001(groupuser1),10(wheel),1007(developers),1008(admins)
```

## 4) Change the primary group

To change a user's primary group, use the lowercase `-g`:

```bash theme={null}
root@control:/home# usermod -g student groupuser1

# Verify primary group change
root@control:/home# id groupuser1
uid=1001(groupuser1) gid=1000(student) groups=1000(student),10(wheel),1007(developers),1008(admins)
```

## 5) Rename a group and change its GID

Use `groupmod -n` to rename a group and `groupmod -g` to change its GID.

Example — rename `developers` to `devs` and set the `devs` GID to `20000`:

```bash theme={null}
# Rename the group
sudo groupmod -n devs developers

# Change the GID of the renamed group
sudo groupmod -g 20000 devs
```

Verify the changes by inspecting `/etc/group` (excerpt):

```bash theme={null}
# Example excerpt from /etc/group showing renamed group and new GID
geoclue:x:994:
clevis:x:993:
sssd:x:992:
gnome-remote-desktop:x:991:
libstoragemgmt:x:990:
pipewire:x:989:
systemd-coredump:x:988:
brlapi:x:987:
wsdd:x:986:
colord:x:985:
setroubleshoot:x:984:
flatpak:x:983:
gdm:x:42:
gnome-initial-setup:x:982:
sshd:x:74:
chrony:x:981:
dnsmasq:x:980:
tcpdump:x:72:
plocate:x:979:
student:x:1000:
opsadmins:x:1004:
user1:x:1006:
admins:x:1008:groupuser1
groupuser1:x:1001:
groupuser2:x:1002:
groupuser3:x:1003:
devs:x:20000:groupuser1
```

## 6) Remove groups

When you need to delete groups, use `groupdel`. Be careful not to remove groups that are required by system services or in active use.

<Callout icon="warning" color="#FF6B6B">
  Warning: Deleting a group that is in use can cause permission and access issues. Verify memberships and service dependencies before running `groupdel`.
</Callout>

Example — delete `admins` and `devs`:

```bash theme={null}
root@control:/home# groupdel admins
root@control:/home# groupdel devs
root@control:/home#
```

## Commands summary

| Command | Purpose | Example |
| - | - | - |
| `groupadd` | Create a new group | `sudo groupadd developers` |
| `groupmod -n <new> <old>` | Rename a group | `sudo groupmod -n devs developers` |
| `groupmod -g <GID> <group>` | Change a group's GID | `sudo groupmod -g 20000 devs` |
| `groupdel` | Delete a group | `sudo groupdel devs` |
| `useradd -m` | Create a user with a home directory | `sudo useradd -m groupuser1` |
| `usermod -G` | Set supplementary groups (replaces list) | `usermod -G developers,admins groupuser1` |
| `usermod -aG` | Append supplementary groups | `usermod -aG wheel groupuser1` |
| `usermod -g` | Change user's primary group | `usermod -g student groupuser1` |
| `id <user>` | Show a user's UID, GID, and groups | `id groupuser1` |
| `grep` | Inspect `/etc/group` | `grep -E 'developers\|admins' /etc/group` |

## Validation & tips

* Always verify group membership with `id <username>` and check `/etc/group`.
* Use `-aG` when you only want to add a supplementary group without removing existing ones.
* Be cautious changing GIDs if files or directories are already owned by the old GID; you may need to update ownership with `chown`.

## Links and references

* [Linux user and group management (man pages)](https://man7.org/linux/man-pages/) — search `groupadd`, `groupmod`, `groupdel`, `usermod`
* [Understanding /etc/group format](https://linux.die.net/man/5/group)
* [Red Hat: User and group administration](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/)

This concludes the demo. Using `groupadd`, `groupmod`, `groupdel`, and `usermod` you can effectively manage primary and supplementary group memberships and control GIDs that appear in `/etc/group`.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/red-hat-certified-system-administrator-rhcsa/module/7940be7b-b644-468b-abba-fe810cb9cc9b/lesson/0f10befb-555f-40ca-a1b2-985d6ef67cbe" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.