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

Modifying a Group — groupmod

sudo groupmod -n newname oldname          # rename a group
sudo groupmod -g 1004 groupname           # change the GID of a group

Deleting a Group — groupdel

sudo groupdel groupname

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