How to Remove Users from Groups in Ubuntu
You remove users from groups in Ubuntu using command-line tools like `deluser` or by directly editing the `/etc/group` file.
A group in Ubuntu acts as a shared permission set for user accounts, controlling their access to files and resources. Removing a user from a group revokes those specific shared permissions for them.
On most Ubuntu systems, including Ubuntu 22.04 LTS, a user can belong to multiple groups, including their primary group and various secondary groups. This structure allows for flexible permission management.
You perform these actions in the Ubuntu terminal, the interface where you input commands. Understanding the correct commands makes this process straightforward.
You remove users from groups in Ubuntu using the command line. Type `sudo deluser username groupname` to remove a specific user from a group. You can verify group membership by running `groups username`.
Removing users from a group in Ubuntu Linux
As we’ve covered, groups help administrators efficiently manage how users access resources. With grouping, you can grant access to a resource to everyone in the group, and they’ll all be able to use it.
Follow the steps below to remove a user from a group if they no longer need access.
Here’s the command format to remove a user from a group:
sudo deluser username groupname
The deluser command is a script that uses the usermod command to add or remove users from groups.
For instance, to remove the user named geekrewind from the developers group, you’d run the following command:
sudo deluser geekrewind developers
A user account must always belong to at least one primary group, which is typically a group named after the user. You can change a user’s primary group if needed.
For example, use the commands below to change the primary group for the user geekrewind to developers.
sudo usermod -g developers geekrewind
This action will move the geekrewind user from its current primary group to the developers group as its new primary group.
You can then remove the account from its previous primary group.
To check which groups a user belongs to, use the command below:
groups username
That should do it!
Conclusion:
- Groups in Ubuntu Linux help administrators efficiently organize or administer user accounts’ access to resources
- The format to remove a user from a group is “sudo deluser username groupname”
- The deluser command uses the usermod command to add or remove users from groups
- It’s important to note that a user account must be a member of one primary group
- You can change the primary group of a user account using the usermod command
- Verifying a user group can be done by running the “groups username” command
How do I remove a user from the group?
Once you find the user you want to remove from your group just tap on it. And then hit remove from group to confirm it hit at remove.
How to remove multiple users together from a group in Linux?
Conclusion. In this article, we explained how to remove all member users from a group in linux. We used the gpasswd command to remove all users. We created a custom script to remove all users from the group as gpasswd only allows one user removal at a time and it does not support the wildcard (*) syntax either.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!