How to Add a User to a Group in Linux

Deepak Prasad
Tested on Red Hat Enterprise Linux 10.2 (Coughlan)
Package shadow-utils 4.15.0-11.el10 (usermod, gpasswd, useradd)
Applies to Ubuntu, Debian, Kali Linux, Linux Mint, Pop!_OS, Raspberry Pi OS, RHEL, Rocky Linux, AlmaLinux, Oracle Linux, CentOS Stream, Fedora
Privilege sudo or root
Scope Add an existing local user to a primary or supplementary group, verify membership, and apply the change in an active session.
Related guides usermod command
groupadd command
adduser command
list groups in Linux
remove user from group

To add an existing user to a supplementary group, run sudo usermod -aG groupname username. That is the command most admins need. The sections below cover verification, Debian shortcuts, changing the primary group, and what to do when a session still behaves like the old membership.


Quick reference

Task Command
Add user to a supplementary group sudo usermod -aG groupname username
Add user to multiple groups sudo usermod -aG group1,group2 username
Debian/Ubuntu shortcut sudo adduser username groupname
Alternate append syntax sudo gpasswd -a username groupname
Change primary group sudo usermod -g groupname username
Verify all groups id username
Group names only groups username
List members of one group getent group groupname
Apply group in current shell newgrp groupname
Create a group first sudo groupadd groupname

Primary group vs supplementary group

Every user has one primary group. New files normally use the process's effective group as their group owner. A setgid directory can instead make new files inherit the directory's group. Commands such as newgrp can change the effective group for a shell, while chgrp changes the group ownership of existing files.

  • Primary group: stored in field 4 of /etc/passwd; shown as gid= in id output.
  • Supplementary groups: additional group memberships shown by id; local supplementary members are typically recorded in the fourth field of /etc/group, while NSS sources such as LDAP or SSSD may provide memberships externally.

Most day-to-day access control uses supplementary groups (docker, sudo, wheel, project groups). Use usermod -aG for those. Use usermod -g only when you want to change the user's primary group.


Add a user to a supplementary group

usermod with -a (append) and -G (supplementary groups) is the portable choice on RHEL, Fedora, and most other distributions.

First confirm the account and target group exist:

bash
id glc_user
output
uid=1014(glc_user) gid=1015(glc_user) groups=1015(glc_user)

Next, confirm the target group exists and has no members yet:

bash
getent group glc_demo
output
glc_demo:x:1014:

glc_user exists and glc_demo is an empty group, so append the user to it:

bash
sudo usermod -aG glc_demo glc_user

usermod prints nothing on success. Check the account again:

bash
id glc_user
output
uid=1014(glc_user) gid=1015(glc_user) groups=1015(glc_user),1014(glc_demo)

The numeric GID 1014 beside glc_demo confirms the supplementary membership is stored. getent group glc_demo should now list glc_user in the fourth field.

WARNING
Always pair -G with -a when adding a group. sudo usermod -G groupname username without -a replaces every supplementary group with the list you pass, which can silently remove sudo, wheel, or docker access.

For flag-by-flag usermod coverage, see the usermod command cheat sheet.


Add a user to multiple groups

List every supplementary group in one -G argument, separated by commas with no spaces:

bash
sudo usermod -aG docker,glc_demo,glc_web glc_user

Confirm the full set:

bash
groups glc_user
output
glc_user : glc_user glc_demo glc_web docker

If any name is misspelled or missing, usermod reports an error. Every group in the list must already exist, so verify names with getent group groupname before running the command.


Debian and Ubuntu: adduser shortcut

On Debian and Ubuntu, adduser username groupname is the distribution-provided high-level command for adding an existing user to an existing group:

bash
sudo adduser glc_user glc_demo

The result is the same supplementary membership you would create with usermod -aG. On RHEL-family systems, stick with usermod or gpasswd. See the adduser command cheat sheet for create-user workflows.


Add an existing user to a group with gpasswd

gpasswd -a appends one user to one group and is equivalent to usermod -aG for a single pair:

bash
sudo gpasswd -a glc_user glc_demo2
output
Adding user glc_user to group glc_demo2

The fourth field of /etc/group should now list the account:

bash
getent group glc_demo2
output
glc_demo2:x:1016:glc_user

To remove a membership later, use gpasswd -d — covered in remove user from group in Linux.


Change a user's primary group

Changing the primary group affects ownership of new files, not just shared directory ACLs:

bash
sudo usermod -g glc_demo glc_user

After that, id -gn glc_user reports glc_demo as the primary group name. Existing files keep their old group until you change them with chgrp.


Verify group membership

Goal Command
UID, primary GID, every group id username
Group names only groups username
Primary group name id -gn username
Who belongs to one group getent group groupname

On hosts with LDAP or SSSD, prefer getent over grep /etc/group so you see directory-backed groups. The list groups in Linux guide walks through getent, id, and /etc/group in more detail.


Apply the new group in an active session

Group changes apply to new login sessions. A shell that was already open still has the old group list.

id glc_user may already show the newly stored membership, while an existing shell belonging to glc_user still has the old group credentials. Run plain id inside that user's existing shell to see the groups available to that running session. GNU id reports the named account when you pass a username; without one, it reports the current process.

Ask the user to log out and back in, or start a fresh login shell:

bash
su - glc_user

To test one supplementary group without a full logout:

bash
newgrp glc_demo

newgrp starts a subshell with glc_demo as an active group. Run id inside that subshell to confirm before testing file or sudo access.


Troubleshooting

Symptom Likely cause Fix
usermod: group 'name' does not exist Group not created or typo Run getent group name; create with sudo groupadd name if missing
User lost other group access usermod -G without -a Re-add every required group with sudo usermod -aG group1,group2 username
id shows the group but permission denied Stale shell session Log out and in, su - username, or newgrp groupname
adduser: user 'x' is already a member of group 'y' Already a member No action needed; verify with groups username
Member missing from getent group but id shows it NSS/cache delay on directory systems Retry after SSSD sync; compare getent passwd and getent group

References


Summary

Adding an existing Linux user to a supplementary group comes down to sudo usermod -aG groupname username, then confirming with id or groups. The -a flag is not optional when you use -G; without it, you replace the user's entire supplementary list and can lock them out of sudo, wheel, or shared project groups.

On Debian and Ubuntu, sudo adduser username groupname is a readable shortcut for the same append operation. Use usermod -g only when you need to change the primary group that owns new files, and use gpasswd -a when you prefer the group-management syntax.

Membership is stored immediately, but running shells keep their existing group credentials. Start a new login session to load the complete updated group list, or use newgrp groupname when you only need to activate one newly added group in the current terminal. For deeper usermod options, group creation, and removal workflows, use the linked cheat sheets and the remove user from group guide.

Frequently Asked Questions

1. What is the command to add a user to a group in Linux?

Run sudo usermod -aG groupname username to append a supplementary group. On Debian and Ubuntu you can also run sudo adduser username groupname. Always include -a with usermod -G or existing secondary memberships are replaced.

2. What is the difference between usermod -g and usermod -G?

usermod -g changes the primary group that owns new files for that user. usermod -G sets supplementary groups and must be paired with -a when you are adding a group instead of replacing the whole list.

3. Why does the user still not have group access after usermod?

Existing processes keep the group credentials they received when they started. Log out and back in, or start a fresh login session with su - username, to load the updated membership. If you only need to activate one newly added group in the current terminal, newgrp groupname starts a subshell with that group active.

4. How do I add a user to multiple groups at once?

Use sudo usermod -aG group1,group2,group3 username with comma-separated names and no spaces. Verify with id username or groups username.

5. How do I check if a user was added to a group?

Run id username for UID, primary GID, and all groups, or groups username for names only. getent group groupname shows the member list stored for that group.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware.

  • Debian
  • Ubuntu
  • Linux
  • Red Hat Enterprise Linux
  • Shell Script
  • System Administration