Managing users and groups is a fundamental skill for any Linux system administrator. Whether you are setting up a personal server, configuring a corporate environment, or managing a development box, understanding how to control access through users and groups is critical for security and organizational clarity. This guide provides a detailed walkthrough on how to add, modify, and manage these entities directly from the command line.

To quickly add a new user and a new group in most Linux distributions, you can use these commands:

  1. Add a group: sudo groupadd mygroup
  2. Add a user: sudo useradd -m myuser
  3. Assign user to group: sudo usermod -aG mygroup myuser

While these commands seem simple, the underlying mechanics of Linux identity management involve specific configuration files, permission sets, and security protocols.

Understanding the Linux Identity Model

Before executing commands, it is essential to understand how Linux identifies users and groups. Linux does not "see" names like "john" or "developers." Instead, it assigns a unique numerical value to every entity.

User ID (UID) and Group ID (GID)

Every user is assigned a User ID (UID). On modern systems, UIDs 0 to 999 are typically reserved for system accounts (like bin, mail, or systemd), while regular users start at UID 1000 and go upwards. Similarly, every group is assigned a Group ID (GID).

Primary vs. Supplementary Groups

In Linux, every user must belong to at least one group, known as the Primary Group. Usually, when you create a user, Linux creates a group with the same name as the user and sets it as the primary. A user can also belong to multiple Supplementary Groups (also called secondary groups). These are used to grant additional permissions, such as access to the sudo group for administrative tasks or the docker group for container management.

How to Create and Manage Groups in Linux

Groups are the primary way to manage permissions for multiple users simultaneously. Instead of changing permissions on a file for ten different people, you assign the file to a group and add those ten people to that group.

Creating a New Group with groupadd

The groupadd command is the standard way to create a new group.