Remove User From Group in Linux

Learn how to remove a user from a certain group in the Linux command line.
Warp Terminal

From its core, Linux is built to have multiple users, and dividing them into certain user groups is one of the best ways to control their access to certain parts of the system.

For example, you can add users to sudo group, so they can access sudo command.

But what if you want to remove a user from added group? Say, a user doesn't need to be sudoer anymore?

Well, in this tutorial, I'm going to show you multiple ways of removing users from group in Linux.

How to remove a user from group in Linux

In this guide, I am going to show you 3 ways to remove a user from the user group in Linux:

  1. Using the gpasswd command
  2. Using the deluser command
  3. By editing the /etc/group file

So let's start with the first one.

1. Using the gpasswd command

The gpasswd command in Linux is used to manage group passwords and its users.

Which means, it can also be used to remove users from group.

But first, let's check the user group. To do so, use the groups command in the following manner:

groups <username>
find usergroup in Linux

To remove a user from the group, you'd have to use the gpasswd command in the following manner:

sudo gpasswd --delete <username> <groupname>

So let's say I want to remove my user sagar from the Tux user group, then, I'd have to use the following:

sudo gpasswd --delete sagar Tux
remove user from group in Linux using gpasswd command

To verify the process, you can check the groups associated to the user:

check groups associated to the user

And as you can see, my user is no longer associated to the Tux group!

2. Using the deluser command (For Ubuntu users only)

On Ubuntu, you get a special command deluser which is specifically built to provide a more user-friendly way of removing users.

To use the deluser to remove user from the group, it needs to be executed in the following manner:

sudo deluser <username> <group>

So let's say I want to remove user sagar from the IF group, then I'd have to use the following command:

sudo deluser sagar IF
use deluser command to remove user from group in Linux

Pretty simple! Isn't it?

3. By editing the /etc/group file

In previous methods, you were given commands which would edit the /etc/group file for you, but here, you'd be doing that manually!

First, open the /etc/group file using the following:

sudo nano /etc/group

Press Ctrl +w and type the group name:

search the name of the group

Once you find the group, you'd find that your username is appended to the group name.

So just remove the username as shown:

remove user from group by editing /etc/group file in Linux

Finally, save changes and exit from the nano text editor.

Now, if you check, your user will be no longer associated to the group:

check user groups for user

Here you have it!

It is time to embrace the terminal

The command line is the most efficient way to perform operations on your Linux system.

But most of the users still hate the terminal because of the way it looks, and typing commands looks too complex.

And at It's FOSS, we firmly believe that Linux users should embrace the terminal and this is why we came up with a series of tutorials to show you how to perform basic tasks:

Linux Command Tutorials for Absolute Beginners
Never used Linux commands before? No worries. This tutorial series is for absolute beginners to the Linux terminal.

I hope you will find this guide helpful!

About the author
Sagar Sharma

Sagar Sharma

A software engineer who loves to write about his experience with Linux. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.

It's FOSS

Making You a Better Linux User

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.