1. Group Management
Creating a Group — groupadd
sudo groupadd groupname # create group, auto-assign GID
sudo groupadd -g 2000 groupname # create group with a specific GID
- By default, the system assigns the next available GID above the last existing one.
- GIDs 1–999 are reserved for system groups.
- Regular groups start from 1000.
Modifying a Group — groupmod
sudo groupmod -n newname oldname # rename a group
sudo groupmod -g 1004 groupname # change the GID of a group
- Renaming a group does not change its permissions on files — the GID stays the same so files are still linked correctly.
Deleting a Group — groupdel
sudo groupdel groupname
- After deletion, any files that were owned by that group will show the raw GID number instead of a name (because the name no longer exists).
- To fix orphaned group ownership on files, use
chown (covered in permissions).
Adding and Removing Users from a Group — gpasswd
sudo gpasswd -a username groupname # add user to group
sudo gpasswd -d username groupname # remove user from group
Checking a User's Groups
id username # shows UID, primary GID, and all groups
groups username # lists all groups the user belongs to
Primary Group vs Secondary Group
| Feature |
Primary Group |
Secondary Group |
| How many per user |
Exactly one |
As many as needed |
| Stored in |
/etc/passwd (GID field) |
/etc/group (members list) |
| Used when creating files |
Yes — new files get this group |
No |
| Permissions on shared files |
Same as secondary — both work |
Same as primary — both work |