Delete user from a group in Linux CLI

Deleting a user from a group in Linux command line interface (CLI) is a simple process that can be accomplished using the command line tool usermod. This tool can be used to modify a user’s account information, including their group membership. In this article, we will go over the steps and examples of how to delete a user from a group in Linux CLI.

Before we begin, it’s important to note that you will need to have root or superuser access to perform these actions. This means that you will need to log in as the root user or use the sudo command to run the commands with superuser privileges.

Steps to delete a user from a group

  1. Open the terminal and log in as the root user or use the sudo command to run the commands with superuser privileges.
  2. Use the groups command to check the current group membership of the user. For example, if we want to check the group membership of the user “john”, we would run the command groups john. This will show us a list of the groups that “john” is currently a member of.
  3. Use the usermod command to delete the user from the group. The basic syntax of the command is usermod -G [group] [user]. For example, if we want to delete the user “john” from the group “developers”, we would run the command usermod -G developers john.
  4. Use the groups command again to verify that the user has been successfully deleted from the group. In this example, running the command groups john should no longer show the group “developers” in the list of groups that “john” is a member of.

Example 1: Deleting a user from a group

Let’s say we have a user named “john” who is currently a member of the group “developers”. We want to remove him from the group “developers”

$ groups john john : john developers 
$ usermod -G developers john 
$ groups john john : john

As you can see in the above example, the user “john” was removed from the group “developers”.

Example 2: Deleting a user from multiple groups

Let’s say we have a user named “jane” who is currently a member of the groups “developers” and “marketing”. We want to remove her from both groups.

$ groups jane jane : jane developers marketing 
$ usermod -G developers,marketing jane 
$ groups jane jane : jane

In this example, the user “jane” was removed from both the “developers” and “marketing” groups.

Conclusion

Deleting a user from a group in Linux CLI is a simple process that can be accomplished using the usermod command. By following the steps and examples outlined in this article, you should be able to easily delete a user from a group in Linux CLI. Remember, you will need to have root or superuser access to perform these actions, and always double-check your work to ensure that the user has been successfully removed from the group.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

four × 3 =

Related Articles