Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to Remove Users from Groups in Linux?
Next article icon

How to Remove Users from Groups in Linux?

Last Updated : 15 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Groups in Linux are an important part of organizing the system's access control. Creating separate groups for separate types of roles of users allows the administrator to manage the access control of the Linux system efficiently.

It is an essential skill to understand how to add, remove, and update users in a group from Linux. In this article, we shall learn various methods for removing a user from a group in Linux using different command line tools. We shall use Kali Linux for demonstration in this article.

Pre-requisites

  • A Linux machine with root privileges.
  • Basic understanding of Linux terminal and commands.

Method 1: Using the `deluser` command

The deluser is a Linux command for deleting users from systems/groups. The syntax of the command is :

deluser <username> <groupname>

Step 1: Check the groups of the user (optional)

First, we shall verify the groups of the user for demonstration purposes. This can be done with the groups command.

groups <username>

In this article, we shall use the 'dummy' user as an example and delete it from different groups.

How to remove a user from a group in linux?
Checking groups of the user dummy

As we can see the user belongs to three groups. In the next step, we shall remove the dummy user from users group.

Step 2: Removing the user from a group

We can modify the userdel command for this purpose:

deluser dummy users

Output:

Picture3
Deleting dummy from users group

As we can see in the response message, the user is removed from the group.

Step 3: Verifying the deletion of the user from the group.

We can verify the result from the same method as used in Step 1.

groups dummy
How to remove a user from a group in linux?
Verification of user deletion from group

As we can verify, the user is removed from the group users.

Method 2: Using the gpasswd command

There is another command, the gpasswd command, to remove users from a group. The syntax of the command is simple:

gpasswd [options...] <groupname>

Now, to delete a user from a group, we use the -d option followed by the username.

gpasswd -d <username> <groupname>

Step 1: Deleting a user from a group using the user command.

We shall use the same user 'dummy' as in the previous method. But, this time we shall delete the user from the 'video' group. The command we need is modified as follows:

gpasswd -d dummy video

We can recheck the existing groups using the same method as in Method 1:

Picture5
Deleting a user from the group using gpasswd command

As we can see, the user was a member of the video group and then, we deleted it using gpasswd.

Step 2: Verifying the result (Optional)

We can again verify using the groups command as before:

groups dummy
Picture6
Verifying the results

As we can verify here, the dummy user is no longer a member of the video group.

Method 3: Editing the /etc/group file

In this method, we shall edit the /etc/group file, which contains information regarding the users, to remove a specific user from the group.

Step 1: Open the file

We can open the file using any editor with root/sudo permissions but, for this tutorial we are using the nano editor.

nano /etc/group

This will open the file. Then, you need to navigate to the line beginning with your group's name. For example, we are removing the dummy from the sudo group so, we shall edit the line beginning with 'sudo'.

2Picture2
Editing the sudo group from /etc/group file to remove dummy user

Step 2: Removing the dummy from the sudo group

Now we need to edit the line containing sudo group and remove the user mentioned in the list of users seperated by ','. The syntax of this file is:

<groupname>:x:<GID>:[users...]

The last column/field contains the usernames seperated by a ','. So, in order to remove a user from the group, we need to delete that user's name from this field in group file. In our case the user is dummy so, we shall remove its name.

The file should look like this after edition:

3Picture3
Edited file.

Now, press Ctrl+S for saving the file and Ctrl+X for exiting the editor. The dummy user is now successfully removed from the sudo group.

Step 3: Verification

We can verify the same using the same verification as previous methods:

groups dummy

This should not show sudo anymore.

4Picture4
Group of dummy user

As we can see, dummy is no longer a member of sudo group.

Conclusion

In this article, we learned three different methods for removing a user from a group in linux. First we used the deluser command and removed a user from a group. Then, we saw how to use the gpasswd command for the same purpose. Lastly, we used a more direct approach and edited the /etc/group file to remove users from a group.


Next Article
How to Remove Users from Groups in Linux?

O

owl0223
Improve
Article Tags :
  • Linux-Unix
  • Geeks Premier League
  • Geeks Premier League 2023

Similar Reads

    How to Remove All Users From a Group in Linux?
    A group is a collection object in the Linux operating system, which associates certain properties and access control to all its members. It is an efficient way for a system administrator to manage Access Control for its users. Groups are an important tool for a system administrator to maintain many
    6 min read
    How to Rename a Group in Linux?
    Renaming a group in a Linux system is a straightforward but essential administrative task. If you're reorganizing your user management structure or enhancing security measures, this quick guide will walk you through the simple steps to rename a group. Linux provides a powerful command, 'groupmod' to
    4 min read
    How to Add User to a Group in Linux
    A group in Linux is a way to put users with similar access and permissions in a collection. By using groups, an administrator can define access control and permissions for all the users belonging to that group. Without groups, the administrator would have to define roles for individual users however
    7 min read
    How to Remove Directory in Linux
    In Linux, directories are used to organize files and other directories into a hierarchical structure. Just like folders in Windows, directories in Linux can contain files, other directories, and links. Removing directories in Linux is a common task that you might need to perform as you manage files
    5 min read
    How to Check the Groups a User Belongs to in Linux?
    Linux is a multi-user operating system, which is designed to support many users operating on the same system through the use of features such as groups. All Linux OS offer the functionality and tools to create and manage many users on a system. One of them is user groups, which are essential for lin
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences