[wpseo_breadcrumb]

Delete a Group from Linux CLI

Update on:
Jan 19, 2023

Deleting a group in Linux can be a simple task when done through the command line interface (CLI). In this article, we will go through the process of deleting a group in Linux using the CLI, with examples to help you understand the process.

Before we begin, it’s important to note that deleting a group will also delete all the users associated with that group. So, it’s important to make sure that you no longer need the group or users associated with it before proceeding with the deletion process.

Step 1: Check the Current Groups

Before we can delete a group, we need to know which groups are currently available on our system. To do this, we use the command “cat /etc/group”. This command will show a list of all the groups currently on the system, along with their group IDs (GID), the users associated with the group, and the group’s password.

For example:

root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:

In this example, we can see that there are four groups on the system – root, daemon, bin, and sys.

Step 2: Delete the Group

Once we know the group we want to delete, we can use the command “groupdel” followed by the group name to delete it. For example, if we want to delete the group “testgroup”, we would use the command “groupdel testgroup”.

It’s important to note that you must have root or superuser privileges to delete a group. If you don’t have the necessary permissions, you will receive an error message.

For example:

$ groupdel testgroup

If the group was successfully deleted, you will not receive any output or error message.

Step 3: Verify the Group has been Deleted

To verify that the group has been deleted, we can use the “cat /etc/group” command again. The group we just deleted should no longer be listed in the output.

For example:

root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:

In this example, we can see that the group “testgroup” is no longer listed, confirming that it has been successfully deleted.

Additional Tips and Tricks

Here are a few additional tips and tricks to help you manage groups in Linux:

  • To delete multiple groups at once, you can use the “groupdel” command followed by the group names separated by spaces. For example, “groupdel testgroup1 testgroup2 testgroup3” will delete all three groups in one command.
  • If you’re not sure if a group exists or not, you can use the “grep” command to search for the group in the “/etc/group” file. For example, “grep testgroup /etc/group” will show the information for the group “testgroup” if it exists.
  • To change the name of a group, you can use the “groupmod” command followed by the new group name and the current group name. For example, “groupmod newgroupname testgroup” will change the name of the group “testgroup” to “newgroupname”.
  • To add a user to a group, you can use the “usermod” command followed by the user name and the group name. For example, “usermod testuser testgroup” will add the user “testuser” to the group “testgroup”.
  • To remove a user from a group, you can use the “gpasswd” command followed by the group name and the user name. For example, “gpasswd -d testuser testgroup” will remove the user “testuser” from the group “testgroup”.
  • To check the groups a user is a member of, you can use the “groups” command followed by the user name. For example, “groups testuser” will show all the groups the user “testuser” is a member of.

Conclusion

In conclusion, deleting a group in Linux using the CLI is a simple task that can be accomplished by using the “groupdel” command. However, it’s important to keep in mind that deleting a group will also delete all the users associated with it, so make sure to double-check before proceeding with the deletion process. Additionally, the above tips and tricks can be helpful in managing and manipulating groups in Linux.

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.

14 − 13 =