How to Remove a User from a Group in Linux

How to Remove a User from a Group in Linux

Hey there, and welcome to this beginner-friendly Linux tutorial from ProgramGuru.org!

Today, we're going to learn how to remove a user from a group in Linux. This is a very common task, especially if you're managing users on a multi-user system.

Why would you remove a user from a group?

Groups in Linux help manage permissions. If a user no longer needs access to a specific resource—like a shared folder or service—you should remove them from the group that controls it.

Step 1: Check the groups a user belongs to

Before removing a user from a group, it's a good idea to check what groups they are currently in.

groups username

For example, to check groups for user john:

groups john
john : john sudo docker developers

This tells us that john is part of the sudo, docker, and developers groups.

Step 2: Remove user from a group

You can use one of the following commands. Let's go over each.

Option 1: Using gpasswd

This is the cleanest way to remove a user from a group.

sudo gpasswd -d john developers
Removing user john from group developers

Option 2: Using deluser (Debian/Ubuntu only)

This works similarly but is available only on Debian-based systems:

sudo deluser john developers
Removing user `john` from group `developers` ...
Done.

Option 3: Using usermod to redefine group membership

This method replaces the user's entire list of supplementary groups, so use it carefully!

sudo usermod -G sudo,docker john

This command reassigns john to just the sudo and docker groups, effectively removing him from developers.

Step 3: Verify the user was removed from the group

groups john
john : john sudo docker

Great! Now the user is no longer part of the developers group.

💡 Pro Tip

Group membership changes take effect immediately for new terminal sessions. If the user is currently logged in, they may need to log out and back in to see the changes.

Conclusion

And that’s it! You’ve successfully learned how to remove a user from a group in Linux. Whether you’re managing permissions for a small team or setting up secure environments, this is a key skill to have.

Thanks for watching, and don’t forget to check out more beginner tutorials on ProgramGuru.org!