LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 11-05-2012, 02:17 AM   #1
kikinovak
Senior Member
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: Slackware, Slackware64
Posts: 1,871

Rep: Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937
Canonical way to remove a user from one or several groups?


Hi,

This is one basic manipulation I always seem to forget. Here goes.

To add a user to a group or a series of groups, I normally use usermod with the -a (append) switch like this:

Code:
# usermod -a -G group1,group2 user
Let's say I want to add user joe to the lp group, I'd do:

Code:
# usermod -a -G lp joe
To add him to the lp and scanner groups, the command would be:

Code:
# usermod -a -G lp,scanner joe
Now what's the canonical way to remove a user from a group or a series of groups? This is the sort of command I rarely use and always seem to forget.
 
Old 11-05-2012, 02:43 AM   #2
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,543

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
gpasswd -d<user> <group>

AFAIK this works only for a single group.

Else if you know the list of groups whom the user (should) belong(s)s to just write (without the -a option):

usermod -G <list of groups not including the one to remove> user

EDIT I use 'gpasswd -a<user> <group>' to add an user to a single group as well.

PS if you want to change the list of groups proposed when you create a new user with the /usr/sbin/adduser Slackware command, just edit the value of the AGID variable (line #110 in Slackware 13.37). But don't tell anybody

PS2 This reminds me that this script should be localized too.

Last edited by Didier Spaier; 11-05-2012 at 03:05 AM. Reason: PS added
 
1 members found this post helpful.
Old 11-05-2012, 03:23 AM   #3
TracyTiger
Member
 
Registered: Apr 2011
Location: California, USA
Distribution: Slackware
Posts: 290

Rep: Reputation: 72
groupmems

I found your question intriguing so I looked around a little and I found the groupmems command. The man page shows the option:

Code:
       -d, --delete user_name
           Delete a user from the group membership list.
I just found it but never used it.

A backup plan would be:

Code:
usermod -G $(id -nG USER| sed -e ‘s/GROUP //’ -e ‘s/ /,/g’) USER
EDIT: Didier's "gpasswd" post looks to be a better solution than groupmems.

Last edited by TracyTiger; 11-05-2012 at 03:39 AM. Reason: Slow Searcher
 
1 members found this post helpful.
Old 11-05-2012, 07:50 AM   #4
kikinovak
Senior Member
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: Slackware, Slackware64
Posts: 1,871

Original Poster
Rep: Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937Reputation: 937
Thanks very much to the both of you !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User groups - manage groups Surka Linux - Security 7 05-02-2012 12:56 AM
How to add/remove groups with user? cola Slackware 6 12-28-2009 03:16 PM
How to identify and remove user groups from an aborted X Windows install? joeebel Linux - Newbie 1 09-29-2009 06:49 PM


All times are GMT -5. The time now is 08:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration