How to Add a User to a Group in Linux

How to Add a User to a Group in Linux

A Linux account may need access to a shared directory or device that is controlled by a group. The usermod command adds an existing account to a supplementary group, an additional membership that does not change its primary group.

I’ll show how to add an account to one or more groups and check its membership afterward.

TL;DR

Add an existing Linux account to an existing supplementary group with this command, then check the account’s group list.

sudo usermod -a -G groupname username
id username
  • Replace the names with an existing login and group.
  • Keep both append options in the command.
  • Start a new login session if access does not update.

What Is a Linux User Group?

A Linux group links accounts to permissions on shared resources.

Every account has a primary group, which Linux uses as the default group for newly created files. An account can also belong to supplementary groups, which add other group associations without replacing that primary setting.

Files normally inherit the creator’s primary group. Membership grants only the permissions configured for that group, such as access to a shared directory or device.

Choose group membership when the group already controls the needed resource. This changes account membership rather than file ownership. For ownership changes, see our guide to changing file ownership with chown.

How to Add a User to a Group in Linux

The usermod command updates an existing account. The operation requires administrative privileges, so use sudo only when your account is authorized to do so.

Step 1: Check the user and group names

Use getent to query the account and group names in the configured account databases before changing membership.

id ubuntu

I ran id ubuntu during this refresh. It returned this account record:

uid=1001(ubuntu) gid=1001(ubuntu) groups=1001(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),44(video),104(lxd),985(hbrowser-ubuntu)
id ubuntu output showing the ubuntu account's Linux group memberships

For another account, replace ubuntu with its login name and sudo with the target group. Check spelling and account records before asking an administrator to create a missing group.

Step 2: Append the user to the group

Use uppercase G to name supplementary groups and lowercase a to append them. Keeping both options matters because omitting a can replace the account’s existing supplementary list.

sudo usermod -a -G groupname username

The command prints no success message. Its manual documents the available options and their behavior.

Step 3: Add the account to multiple groups

Pass multiple existing group names as one comma-separated value, without spaces. This form adds both named groups to the account.

sudo usermod -a -G developers,video username

Use group names separated by commas, with no spaces. Check unfamiliar names with getent first.

Step 4: Verify membership

Query the account with id to see its primary and supplementary groups. I ran id ubuntu during this refresh, and the captured output showed the ubuntu account’s group memberships.

id ubuntu output showing the ubuntu account's Linux group memberships

Check that your target group appears in the groups field. The screenshot shows the complete output for the ubuntu account, including its primary group and supplementary memberships.

id username
groups username

Verify Membership and Handle Common Issues

A successful membership change may not affect a session that was already open. Check the account and resource before repeating the update.

CaseSymptomFix
Account missingAccount lookup returns no entryCheck the login spelling and account source.
Group missingGroup lookup returns no entryCheck the group name. An administrator can create it separately.
Other memberships lostPreviously listed groups are absentReview whether append was omitted. Restore intended memberships carefully.
Access still deniedMembership appears, resource remains unavailableStart a new login session and check the resource’s permissions.

Troubleshooting membership

Use the command in the matching row to check the reported symptom before changing membership again.

CaseSymptomCommand and fix
Group is missingThe target group does not appear for the account.Run getent group groupname. Correct the name or ask an administrator to create the group.
Access is still deniedid username lists the group, but a program still rejects access.Start a new login session, then inspect permissions with ls -l /path/to/resource.
Unexpected membershipsThe account’s group list differs from the intended list.Run id username. Review the command options before making another change.

List groups and remove a membership

These commands answer different checks. Run the broad lookup for available group records, or add a name to query one record.

Use getent group to query the configured group database, which can return local or directory-backed records.

getent group
groups username

The first command lists groups available through the account database. The second shows groups assigned to the named account. A specific lookup is useful when that full list is too long to scan.

getent group groupname

A group record uses colon-separated fields. Reading the fields helps distinguish the group name from its numeric ID and listed members.

FieldMeaningWhat to check
Group nameThe group’s text name.Match the name used in the usermod command.
Password fieldA reserved field in the record.It is not the group name or ID.
GIDThe numeric group identifier.Use it to distinguish groups with similar names.
Member listComma-separated account names listed for the group.Check the account entry when diagnosing an absent membership.

The group file manual documents this record format. A lookup result helps identify which field needs attention, but the account-wide id output remains the direct check for that login’s group list.

To remove a supplementary membership, use gpasswd with its delete option and the account name. Check the account and group names before running the command.

sudo gpasswd -d username groupname

Then inspect the account’s group list again. If resource access remains the issue, inspect its configured permissions instead of changing unrelated memberships.

For adjacent account tasks, see Linux user administration and our guides to protecting files with passwords and creating directories.

Conclusion: Append, Then Verify

Programs in an existing session may retain their previous group list, so start a new session if access does not update. The usermod manual and id manual document the command options and membership output.

FAQ

These answers cover common group membership questions.

How do I add a user to multiple groups in Linux?

Use sudo usermod -a -G group1,group2 username. Separate existing group names with commas and no spaces.

Why does the user still lack access after I add the group?

The current login session may still have its old group credentials. Log out and back in, then check membership again.

How can I check a user’s groups?

Run id username or groups username and look for the target group in the output.