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.
To remove user from group, there are so many ways to do it. Choose 1 of the following subsections that suits you.
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
Yo can also use deluser command using the following pattern:
$ deluser <user> <group>
Following the example above, it is:
$ deluser user2 mygroup
Yo can also use gpasswd command using the following pattern:
$ gpasswd -d <user> <group>
Following the example above, it is:
$ gpasswd -d user2 mygroup
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.