Quick take: Use sudo groupadd developers to create a group, groups username to see a user's groups, and sudo usermod -aG developers alice to add a member. Groups are how Linux shares access across multiple users.

Introduction

Groups let several users share access to files and resources, which is the foundation of multi-user permission management. The groupadd command creates groups, the groups command shows who belongs to what, and a few related commands round out membership management.

Syntax

The basic syntax of the groupadd and groups command is:

groupadd [OPTIONS] GROUP
groups [USER]

Common Options and Parameters

The most useful options and parameters for the groupadd and groups command:

OptionDescription
groupadd NAMECreate a new group.
groupadd -g GID NAMECreate a group with a specific GID.
groupadd -r NAMECreate a system group.
groups [user]Show the groups a user belongs to.
gpasswd -a user grpAdd a user to a group.
gpasswd -d user grpRemove a user from a group.
groupdel NAMEDelete a group.

Practical Examples

Real groupadd and groups commands you can run today:

# Create a group
sudo groupadd developers
# See your own groups
groups
# See another user's groups
groups alice
# Add a user to a group
sudo usermod -aG developers alice
# Remove a user from a group
sudo gpasswd -d alice developers
# Delete a group
sudo groupdel developers

Tips and Best Practices

  • Use groups to grant shared access to a directory: set the directory's group and chmod g+rws so new files inherit it.
  • groups username is the quick way to audit what a user can access through group membership.
  • Every user has one primary group (used for new files) and any number of supplementary groups.

Final Thoughts

Groups are Linux's mechanism for sharing access among users, and groupadd plus groups are the tools to create and inspect them. Combine groupadd with usermod -aG to build teams that share directories and resources, and use groups to audit membership. They are the backbone of clean, scalable permission management.

FAQ: groupadd and groups Command in Linux

How do I create a group in Linux?+

Use sudo groupadd groupname, for example sudo groupadd developers. Add -g GID to set a specific group ID or -r for a system group.

How do I see what groups a user belongs to?+

Run groups username, or just groups for yourself. The id username command also shows group IDs alongside the names.

How do I add a user to a group?+

Use sudo usermod -aG groupname username (append safely) or sudo gpasswd -a username groupname. The user must re-login for it to take effect.

How do I remove a user from a group?+

Use sudo gpasswd -d username groupname, which removes that single membership without affecting the user's other groups.

What is the difference between a primary and supplementary group?+

A user has one primary group, used as the group owner of files they create, and any number of supplementary groups that grant additional access. groups lists all of them.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support