what command is reverse operation of "usermod -a -G groupname username"

Asked by dinar qurbanov

how to remove a user from a group?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Robert Di Gioia
Solved:
Last query:
Last reply:
Revision history for this message
Best Robert Di Gioia (digioiar) said :
#1

Hi

The easiest way is to edit /etc/group manually, but you need to be careful not to mess up the file format. You can do this by opening a terminal and entering the following command. The system will ask you to enter your password, type it in and press enter even though you won't see anything while typing the password, it is ok.

gksudo gedit /etc/group

This starts the gedit editor, which is much like notepad. Find the group you want to remove the user from, and delete the user id from that line. make sure you take care of any commas too.

If you don't like editing files the files directly, then use this command to find out what groups the user is in

groups userid

where userid is the user in question. This command lists all of the groups the user is in. Then you use this command to modify the user

sudo usermod -G groups_to_remain_in userid

where groups_to_remain_in is all of the groups listed in the groups command EXCEPT the one that you want to remove from the user, seperated by commas with no white space between the groups that the user still needs to be a part of.

Hope this helps.

Revision history for this message
dinar qurbanov (qdinar) said :
#2

Thanks Robert Di Gioia, that solved my question.