Create a group with sudo groupadd developers, add a user to it with sudo usermod -aG developers alice, and delete it with sudo groupdel developers. Groups let you give the same file permissions to several users at once instead of setting permissions per person. This guide covers the core linux groups groupadd commands, how to list memberships and how group ownership affects files.
Group data lives in /etc/group, and each user also has one primary group stored in /etc/passwd.
A group is a named set of users with a numeric group ID (GID). Every file has an owner and a group owner, and the permission bits include a separate set for the group. If alice and bob are both in developers, a file owned by group developers with mode rw-rw---- is readable and writable by both and closed to everyone else.
Each user has two kinds of group membership:
/etc/passwd and used as the group of new files the user creates;/etc/group, which add further access.Most distributions create a private primary group with the same name as the user, so the files you create are not shared by default.
Create a group:
Choose the GID explicitly if you need stable IDs across servers:
Create a system group for a service with -r:
Delete a group:
groupdel refuses to delete a group that is the primary group of an existing user. Change that user's primary group first or delete the user. Files owned by the deleted group keep the numeric GID and show it instead of a name, so reassign them with chgrp before deleting.
Rename a group with groupmod:
The safe way to add a user to a supplementary group is usermod -aG:
The -a means append. Without it, -G replaces the user's entire supplementary list, which can silently remove sudo access. This is one of the most common administration mistakes.
Debian and Ubuntu also provide gpasswd and adduser:
Changing a primary group uses lowercase -g:
A running shell keeps the groups it had at login. After adding yourself to a group, log out and in again, or start a new group-aware shell for testing:
The getent group line has four fields: name, password placeholder, GID and a comma-separated member list. Note that the member list in /etc/group only names supplementary members. Users whose primary group is this group may not appear in it.
To see every group on the system, run getent group, or cut -d: -f1 /etc/group for just the names.
A typical task is a project directory where all members can read and write each other's files.
The leading 2 is the setgid bit. On a directory it makes new files inherit the directory's group, rather than the creator's primary group. Without it, files created by alice get the group alice, and bob may not be able to edit them.
Check the result:
The s in the group execute position confirms setgid.
/etc/gshadow can name group administrators, who may add or remove members with gpasswd without full root rights. Group passwords exist for use with newgrp but are almost never used today. Prefer sudo rules, ACLs or proper membership instead.
Use sudo usermod -aG groupname username. The -a keeps the existing supplementary groups.
Running processes keep the groups they started with. Log out and back in, or run newgrp groupname for a shell that has the new group.
Run getent group groupname. Also check users whose primary group is that group, for example with awk -F: '$4 == GID' /etc/passwd using the numeric GID.
Yes. A user has one primary group and many supplementary groups, with a system limit that is far higher than you will normally need.
Use groupadd and groupdel to create and remove groups, usermod -aG to add members without losing existing groups, and groups, id and getent group to inspect them. For shared directories set the group with chgrp and the setgid bit with chmod 2775, and remember that membership changes apply only to new login sessions.