Remove User from Linux Group
Sometimes, you would just want to remove a user from a particular Linux Group without deleting them both. This section guides you on how to do that.
Remove User From Group
To remove user from group, there are so many ways to do it. Choose 1 of the following subsections that suits you.
Manual Removal
You can manually edit the /etc/group
file by searching the group name and remove the user from the list. Example, to remove "user2" from "mygroup":
mygroup:x:1274:user1,user2,user3
to
mygroup:x:1274:user1,user3
Using deluser
Yo can also use deluser command using the following pattern:
$ deluser <user> <group>
Following the example above, it is:
$ deluser user2 mygroup
Using gpasswd
Yo can also use gpasswd command using the following pattern:
$ gpasswd -d <user> <group>
Following the example above, it is:
$ gpasswd -d user2 mygroup
Using usermod
Yo can also use usermod command to flush all supplement groups first then append the required group individually:
$ usermod -G "" <user>
$ usermod -a -G <all wanted groups> <user>
Following the example above, it is:
$ usermod -G "" user2
$ usermod -a -G groupX,groupT,groupV user2
That's all for removing users from group.