To remove a user from a group in Linux, you use the gpasswd -d command or edit the /etc/group file directly. The most common method is sudo gpasswd -d username groupname, which works on all major distributions and takes effect immediately.
Understanding Linux Groups
Linux uses groups to manage permissions for multiple users at once. Every user has a primary group (set in /etc/passwd) and can belong to several supplementary groups (listed in /etc/group). When you remove a user from a group, you are almost always removing them from a supplementary group, since the primary group is tied to the user account itself.
Group membership controls access to files, directories, and system resources. For example, a user added to the docker group can run Docker commands without sudo, and a user in the sudo group can execute administrative commands. Removing a user from such a group revokes those privileges immediately, though the user may need to log out and back in for the change to affect their current session.
The gpasswd Command (Easiest Method)
The gpasswd utility is part of the shadow-utils package and is available on virtually every Linux distribution. The syntax is straightforward:
sudo gpasswd -d username groupname
For example, to remove user alice from the docker group:
sudo gpasswd -d alice docker
The command outputs Removing user alice from group docker and exits. If the user is not a member, it prints an error like gpasswd: user 'alice' is not a member of 'docker'.
You can verify the removal with:
groups alice
or
id alice
Both show the user’s current group memberships. The change is immediate for new logins; existing sessions may retain the old group until the user logs out and back in.
Editing /etc/group Directly
If you prefer a manual approach or gpasswd is not installed (rare), you can edit the /etc/group file. Each line follows the format:
groupname:x:GID:user1,user2,user3
To remove a user, open the file with a text editor as root:
sudo nano /etc/group
Find the line for the group, delete the username from the comma-separated list, and save. For example, changing docker:x:994:alice,bob to docker:x:994:bob removes alice.
Be careful not to leave a trailing comma if the user was the only member. The file is read by the system, so the change takes effect immediately, but again, active sessions may not see it until re-login.
Using usermod to Remove a User from All Groups
If you need to remove a user from all supplementary groups at once, use usermod with the -G flag and an empty list:
sudo usermod -G "" username
This sets the user’s supplementary group list to empty. Note that this does not change the primary group; that remains as defined in /etc/passwd. To also change the primary group, you would use usermod -g newgroup username, but that is a different operation.
This command is useful when you want to strip a user of all group-based permissions (like removing them from sudo, docker, and www-data in one go). It is also handy in scripts.
Removing a User from a Group in Specific Scenarios
While the commands above work everywhere, some contexts have their own tools:
- Debian/Ubuntu:
gpasswdis standard. You can also usedeluser username groupname(from theadduserpackage). - Red Hat/Fedora:
gpasswdworks, butusermod -Gis common. There is nodeluserby default. - Arch Linux:
gpasswdis available. Some prefer editing/etc/groupdirectly. - LDAP/Active Directory: If users are managed by a central directory, you must use the directory’s tools (e.g.,
ldapmodifyor AD Users and Computers) rather than local commands.
Common Mistakes and Pitfalls
The most frequent error is forgetting that the user must log out and back in for the change to affect their current session. Many users report that they still see the group after removal; that is because the kernel caches group memberships at login. The fix is to have the user log out completely (or run su - username to start a fresh login).
Another mistake is editing /etc/group and accidentally removing the wrong user or leaving a syntax error. Always make a backup before editing:
sudo cp /etc/group /etc/group.bak
Also, do not remove a user from the sudo or wheel group if they are the only administrator on the system—you could lock yourself out. Always have a root password or another admin user as a fallback.
Frequently Asked Questions
How do I remove a user from a group without sudo?
You cannot. Modifying group membership requires root privileges because it affects system security. If you do not have sudo access, ask the system administrator to do it for you.
Why does the user still see the group after I removed them?
Group memberships are read at login and cached by the kernel. The user must log out and log back in (or you can use su - username to force a fresh session) to see the change.
What is the difference between primary and supplementary groups?
Every user has exactly one primary group, defined in /etc/passwd. Files created by the user are assigned that group by default. Supplementary groups are additional groups listed in /etc/group that grant extra permissions. Removing a user from a group always refers to supplementary groups; you cannot remove the primary group without changing it to another group.
Can I remove a user from a group using the usermod command?
Yes, but only by specifying the full list of groups you want the user to remain in. For example, sudo usermod -G wheel,www-data alice sets alice’s supplementary groups to exactly wheel and www-data. If you want to remove from one group while keeping others, you must list all the ones you want to keep.
Does removing a user from a group delete the user account?
No. Removing a user from a group only revokes that group’s permissions. The user account remains active with its home directory and primary group intact. To delete the account entirely, use userdel.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- How to Move Data to a New Samsung Galaxy Phone
- Pixel C vs Surface Pro: Key Differences
- iPhone X vs iPhone: Key Differences Explained
- Chromebook Won’t Charge: How to Fix
- How to Delete Photos on Google Drive
- Firefox Bookmark Management Tips & Tricks