Remove Linux User From a Secondary Group ( Supplementary Groups )
Q. User tom is a member of a group called sales and printer. I'd like to remove tom from a group called printer without editing any user configuration text files stored at /etc/ directory?
A. /etc/groups file defines group membership for each user. usermod command has -G option to set a list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. If the user is currently a member of a group which is not listed, the user will be removed from the group.
Step # 1: Find out user group identity
Use id command:
# id -nG {user-name}
# id -nG tom
Output:
sales printer
Step # 2: Remove user from printer group
Use the following syntax:
# usermod -G {groupname1,groupname2,...} {username}
To keep membership for sales only group (remove user tom from printer group), enter:
# usermod -G sales tom
# id -nG tom
Output:
sales
The following example remove user vivek from all groups except admin, audio, video and powerdev group:
# id -nG vivek
Output:
vivek adm dialout cdrom floppy audio dip video plugdev scanner netdev lpadmin powerdev admin
Modify group membership, enter:
# usermod -G admin, audio, video, powerdev vivek
# id -nG tom
Sample output:
vivek audio video powerdev admin
For more information, read usermod(8) command man page:
$ man usermod
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Linux / UNIX FAQ:
- Howto: Linux creating user account under group
- Howto: Linux add user to group
- Find files that do not have any owners or do not belong to any user under Linux/UNIX
- Linux set or change user password how to
- Linux add a user using command line tools
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!
Tags: delete group membership, group id, group identity, group membership, id command, linux delete user from group, user group, usermod command ~ Last updated on: March 3, 2008



Recent Comments
Today ~ 2 Comments
Today ~ 37 Comments
Today ~ 46 Comments
Yesterday ~ 2 Comments
Yesterday ~ 9 Comments