How to Add Users to a Group in Linux
Add a user to a group in Linux with usermod or gpasswd, check the result, make it take effect without logging out, and remove the user again.
2 min readBy Shailabh
Reviewed by the AmazingRDP technical team

Setting up users for a team? A Linux VPS gives you root access to manage them. See Linux VPS from $6.99
Groups are how Linux gives several users the same rights: to read a folder, to use Docker, to run commands as administrator. Adding a user to a group is one command. The details around it are where people trip.
The short answer
sudo usermod -aG groupname username
For example, to add alex to the group developers:
sudo usermod -aG developers alex
Do not leave out the -a. -G alone means "these are the user's groups, and no others": it removes the user from every other group, including sudo. With -a (append) the group is added to the existing ones.
See which groups exist and who is in them
groups alex
id alex
getent group developers
getent group
The first two show the groups of a user; the third shows the members of one group; the fourth lists all groups.
Create a group first, if needed
sudo groupadd developers
Several groups at once
sudo usermod -aG developers,docker,www-data alex
Separate the names with commas and no spaces.
Other commands that do the same
| Command | Where |
|---|---|
sudo gpasswd -a alex developers | Every distribution |
sudo adduser alex developers | Debian and Ubuntu |
Both add to the existing groups and cannot remove others by mistake, which makes them the safer habit.
Why it does not work straight away
A user's groups are read at login. Someone who is signed in keeps the old list until they sign out and in again. For the current terminal only, this applies the new group at once:
newgrp developers
Services are the same: a running service that should gain the group has to be restarted. Over SSH, close the connection and connect again.
Remove a user from a group
sudo gpasswd -d alex developers
On Debian and Ubuntu, sudo deluser alex developers does the same. Neither deletes the user.
Primary and secondary groups
Every user has one primary group, normally with the same name as the user; new files belong to it. All other memberships are secondary groups, and those are what the commands above change. To change the primary group, which is rarely needed:
sudo usermod -g developers alex
Create a user with groups in one step
sudo useradd -m -s /bin/bash -G developers,sudo sam
sudo passwd sam
Groups you will meet
| Group | Membership gives |
|---|---|
sudo (Debian, Ubuntu), wheel (Fedora, AlmaLinux, Rocky) | Administrator rights through sudo. See granting su or sudo access |
docker | Use of Docker without sudo. This is as good as root access; give it only to people you would give root to |
www-data | The web server's group on Debian and Ubuntu |
adm | Reading system logs |
When groups are not enough
A file has exactly one group. When two groups need different rights on the same folder, use access control lists: see setfacl in Linux.
For a server to manage users on, see our Linux VPS plans. Related: fix "sudo: command not found".
Questions
How do I add a user to a group in Linux?
Run sudo usermod -aG groupname username.
What does -aG mean in usermod?
-G sets the secondary groups and -a appends to the existing ones. Without -a the user is removed from all other groups.
Why is my new group not active?
Groups are read at login. Sign out and in again, or run newgrp groupname in the current terminal.
How do I remove a user from a group?
Run sudo gpasswd -d username groupname.