Open In App

How to Create, Delete, and Modify Groups in Linux

Last Updated : 08 Nov, 2025
Comments
Improve
Suggest changes
2 Likes
Like
Report

In Linux, a group is a collection of user accounts. Groups are a fundamental security and organization tool, allowing you to manage permissions for multiple users at once, rather than one by one.

Using groups is essential for efficient and secure system administration. It allows you to:

  • Share Files: Grant read, write, or execute permissions to a specific "team" (e.g., developerssales) for a project directory.
  • Control Access: Give specific users elevated privileges (e.g., adding them to the sudo group).
  • Manage Services: Allow users to run specific services without giving them full root access (e.g., adding them to the docker or www-data group).

For example: You have a group of web developers. Rather than granting all developers read access to the project files individually, you create a group named devs and add all members to it. Then you establish permissions so devs can read and write in the project directory. All done in one step, everyone has the access they require.

Types of Linux Groups:

There are two types of groups in linux:

  • Primary Group: When you create a new user, Linux also creates a group with the same name (e.g., user rahul joins primary group rahul). All new files created by rahul are, by default, owned by the rahul group. A user can only have one primary group.
  • Secondary Group: These are the extra groups you add a user to (like sudodocker, or developers). They are used to grant additional permissions beyond the user's primary group. A user can be in many secondary groups.

For more details refer Group Management in Linux

How to Create a Group in Linux

Creating a groups on Linux enables us to set functionally similar users under one group for easier access management. This is useful for teams like developers, designers, or admins that need to collaborate on files in a centralized location.

Command to Create a New Group:

sudo groupadd groupname

How to View All Groups in Linux

To check for existing groups on a Linux machine, you can execute a couple of commands which will show the groups available.

Command to List All Groups:

cut -d: -f1 /etc/group      # This command displays a simple list of all group names on your system
OR
getent group

How to Check Group Membership of a User

To check which groups a given user belongs to, the groups command can be used.

Syntax:

groups username

How to Add a User to a Group

Adding a user to a group lets them access shared files, folders, and permissions tied to that group. This is useful when managing teams or giving specific rights.

Syntax:

sudo usermod -aG groupname username

Breakdown:

  • -a (Append): This is CRITICAL. It adds the user to the group.

    Warning: If you forget -a, you will remove the user from all other groups and add them only to this one.

  • -G (Groups): Specifies the supplementary Group(s) to add the user to.

After adding a user to a new group, that user must log out and log back in for the new permissions to take effect.

How to Remove a User from a Group

When a user is removed from the group, that user loses the resources and privileges that are available through that group.

Syntax:

sudo gpasswd -d username groupname           # This command deletes the user from the specified group

How to Change a User's Primary Group

Change a User’s Primary Group: In Linux, each user has one primary group, which becomes the default group ownership for all new files they create.

Syntax:

sudo usermod -g newgroup username

How to Delete a Group in Linux

Removing a group from the system does delete the users from that group and all their details are retained irrespective of the specific group.

Syntax:

sudo groupdel groupname

How to Modify a Group in Linux

You can use groupmod to rename a group. This is convenient when names for groups need to be regularized or changed.

Syntax:

sudo groupmod -n newgroup oldgroup

Common Use Cases for Managing Groups

Groups in Linux are powerful when you want to organize users and control access without setting permissions individually

ScenarioWhy Use Groups
File sharing within a teamInstead of giving file access to each user manually, assign all members to a group so they automatically share access.
Admin vs regular user accessHelps create a secure environment by grouping users based on roles. Admins can have elevated permissions while regular users stay restricted.
Server managementGroups allow certain users to execute administrative tasks (like using sudo) without affecting others.
Educational institutionsSchools and colleges use groups to separate permissions for students, teachers, and IT staff. Each group can access only what's relevant to them.

Command Sheet

CommandWhat It Does
groupadd [name]Creates a new, empty group.
groupdel [name]Deletes an existing group.
groupmod -n [new] [old]Modifies a group's properties (e.g., renames it).
usermod -aG [group] [user]Appends a user to a supplementary Group. (Most common)
gpasswd -d [user] [group]Deletes a user from a group.
usermod -g [group] [user]Changes a user's primary group.
groups [user]Lists all groups a user is a member of.
getent groupLists all groups on the system.

Conclusion

Linux groups are a core part of system management and user access control. From creating a group for a development team to removing outdated permissions, group commands let you manage multiple users efficiently and securely. With just a few commands—like groupadd, usermod, groupdel, and groupmod—you can organize users, control access to files and tools, and keep your Linux system clean and secure.

Whether you're managing users in a school, office, or cloud server, groups make it easier to apply the right access to the right people—without confusion or clutter. In a world where data security and user management matter more than ever, mastering group management is a simple yet powerful skill every Linux user should have.


Article Tags :

Explore