[wpseo_breadcrumb]

Delete user from a group in Linux CLI

Update on:
Jan 19, 2023

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.

Related Posts

Upgrading system Off-line with ISO and Yum

Upgrading a system can be a daunting task, especially if it is an off-line system. An off-line system is one that is not connected to the internet and cannot access online resources. The good news is that you can still upgrade your system even when it is not connected...

Configuring Yum

Introduction Yum (Yellowdog Updater, Modified) is a package manager for Red Hat based Linux distributions, including Fedora and CentOS. It helps in managing and updating the software packages on the system, including their dependencies and conflicts. In this article,...

Yum Commands and Options

Introduction Yum is a package manager used in Red Hat-based systems like Fedora, CentOS, and Red Hat Enterprise Linux. With Yum, users can easily install, update, and remove packages from the terminal. In this article, we'll explore the basic Yum commands and their...

Setting up a YUM Repository

Introduction YUM (Yellowdog Updater, Modified) is a popular open-source package management system used to install, update, and remove packages in Linux distributions such as Fedora, Red Hat Enterprise Linux (RHEL), and CentOS. YUM makes it easier to manage packages by...

Follow Us

Our Communities

More on Linux

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published.

1 + three =