Remove User from a Group Using “gpasswd” Command in 3 Steps

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

In Linux, groups are a way to control access and share resources where different groups enjoy different privileges. An administrator can remove a user from a group for different reasons as changing job responsibilities, security concerns etc. The gpasswd command is a powerful tool to add or remove a user and manage group passwords. In this article, I will show you how to remove a user from a group using the gpasswd command in Ubuntu.

Process flow chart to remove user from a group using “gpasswd” Command:Process flow chart to remove a user from a group using the gpasswd command

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS

3 Steps to Remove a User from a Group using the gpasswd Command

In my Ubuntu, there is a user by the name of “walid” and he is in a group named “mygroup”. Now I will remove user walid from the mygroup group using the gpasswd by the following three steps:

Step 01: View Current Groups in Ubuntu

In the beginning, I will check the current groups of the user “walid”. To do so, follow the steps:

  1. Launch an Ubuntu Terminal by pressing CTRL+ALT+T.
  2. Insert the following command:
    groups walid
    EXPLANATION
    • groups: Allows to view and manage groups.
    • walid: Name of the user.

    Showing current groups of the userThis shows the groups that the user “walid” joined. Also, there is a group “mygroup” and I will remove the user from that group.

Step 02: Remove the User from a Group Using “gpasswd” in Linux

In this step, I will use the gpasswd to remove the user “walid” from group “mygroup”. Check the steps below:

  1. Copy the command below on the Ubuntu Terminal:
    Command Syntax >
    sudo gpasswd -d USERNAME GROUPNAME

    sudo gpasswd -d walid mygroup
    EXPLANATION
    • sudo: Grants root privileges.
    • passwd: Adds or removes users and manages group passwords.
    • -d: Deletes user.
    • walid: Name of the user.
    • mygroup: Name of the group.
  2. Provide the password (if necessary).
  3. Press the ENTER button from the keyboard.Removing user from a groupIn the output, you should see something like “Removing user walid from group mygroup”.


Step 03: Check if the User is Removed Successfully in Linux

Finally, I will check if removing of user walid from group mygroup was successful. Follow the steps to verify it:

  1. Write the following command on the terminal:
    groups walid
    EXPLANATION
    • groups: Allows to view and manage groups.
    • walid: Name of the user.
  2. Hit the ENTER key from the keyboard.Groups after removing user from a groupIf you look carefully, you will see there is no group by the name of mygroup here. So I have successfully removed user “walid” from group “mygroup”.

Conclusion

In this article, I have tried to show you how to remove a user from a group in Ubuntu in a simple and comprehensive way. I hope you find my effort helpful.

People Also Ask

How to remove a user from a group using “gpasswd” command?

To remove a user from a group using gpasswd command, write the following code in your terminal:

sudo gpasswd -d walid mygroup

This command will delete the user “walid” from the group called “mygroup”.

What is gpasswd in Linux?

The gpasswd is a command that is used to administer groups in Linux. It writes group information in /etc/gshadow and /etc/group files. Using this command, an administrator can define group administrators and members.

How can I delete my group members?

There are multiple ways to delete a user from a group. However, the best approach is using the gpasswd command with option -d like: sudo gpasswd -d USERNAME GROUPNAME.

How to remove a password from a group in Linux?

You can use the gpasswd to remove passwords from a group. To do that, you need to use the option -r. For instance, if you have a group named “mygroup”, you can use the following command to remove the password from that group:

sudo gpasswd -r mygroup

How do you delete a group in Linux?

To delete a group in Linux, you need to use the groupdel command. You need to provide the group name as well. For example, if I want to delete a group named “mygroup”, I will use the following command:

sudo groupdel mygroup


Related Articles

4.8/5 - (13 votes)
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

Leave a Comment