Operations 6 min read

Remove Users from Linux Groups with usermod, gpasswd, and /etc/group

This tutorial explains how to delete a user from one or multiple Linux groups using the usermod and gpasswd commands, as well as by manually editing the /etc/group file, with step‑by‑step examples and complete command output.

ITPUB
ITPUB
ITPUB
Remove Users from Linux Groups with usermod, gpasswd, and /etc/group

Linux users belong to a primary group and optional secondary (supplementary) groups, defined in /etc/group. This guide shows three ways to remove a user from groups: the usermod command, the gpasswd command, and manual editing of /etc/group.

Creating a test user and groups

First, a test user is created, which automatically creates a primary group with the same name: $ sudo useradd -m testuser A password is set for the new account: $ sudo passwd testuser Two supplementary groups are added:

$ sudo groupadd testgroup1
$ sudo groupadd testgroup2

The user is then added to the new groups and to root:

$ sudo usermod -a -G root testuser
$ sudo usermod -a -G testgroup1 testuser
$ sudo usermod -a -G testgroup2 testuser

Viewing /etc/group confirms the memberships.

Finding a user’s groups

Two commands provide the same information:

$ groups testuser
$ id -nG testuser

Removing a user from groups with usermod

The usermod command can replace the list of supplementary groups for a user. To keep the user only in the root group (removing it from testgroup1 and testgroup2), run: $ sudo usermod -G root testuser Result:

$ groups testuser
testuser : testuser root

Multiple groups can be specified as a comma‑separated list, e.g.:

$ sudo usermod -G root,testgroup1 testuser

Removing a user from groups with gpasswd

The gpasswd -d command deletes a user from a specific group. Examples:

$ sudo gpasswd -d testuser root
Removing user testuser from group root
$ groups testuser
testuser : testuser testgroup1 testgroup2
$ sudo gpasswd -d testuser testgroup1
Removing user testuser from group testgroup1
$ groups testuser
testuser : testuser testgroup2

Manual removal by editing /etc/group

Open /etc/group with a text editor and delete the user name from the desired group lines. After editing, the relevant lines look like:

testuser:x:1001:
testgroup1:x:1002:
testgroup2:x:1003:

After saving and restarting (or re‑reading the file), the user is removed from those groups:

$ groups testuser
testuser : testuser root

Conclusion

The tutorial demonstrates how to remove a Linux user from groups using usermod, gpasswd, and by directly editing /etc/group. These commands work on any Linux distribution such as Ubuntu, CentOS, or Fedora.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLILinuxUser Managementgroup-managementgpasswdusermod
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.