Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Which command should I use to remove a user from a group in Debian?

When adding a user to a group, it can be done with:

usermod -a -G group user

However, I could not find a similar command (accepting a group and user as arguments) for removing the user from the group. The closest I could get is:

usermod -G all,existing,groups,except,for,group user

Is there a command like usermod OPTION group user with OPTION an option to make usermod (or a similar program) remove the user from group?

share|improve this question
add comment

5 Answers

up vote 53 down vote accepted

You can use gpasswd:

# gpasswd -d user group

then the new group config will be assigned at the next login, at least on debian. If the user is logged in, the effects of the command aren't seen immediately.

share|improve this answer
    
+1 good one @hesse :-) –  Nikhil Mulley Jan 20 '12 at 16:41
1  
Perfect thanks! gpasswd -a user group for adding the user to the group seems also nicer, especially if a typo has made and the -a option gets dropped. –  Lekensteyn Jan 20 '12 at 16:43
add comment

On Debian, the adduser package contains a deluser program which removes a user from a group if you pass both as arguments:

deluser user group

If your distribution doesn't have adduser, you can edit /etc/group and /etc/gshadow manually.

vigr
vigr -s
share|improve this answer
4  
I did not know of programs like vigr and vipw. Very useful in case the manpages are too far away :) –  Lekensteyn Jan 20 '12 at 16:47
add comment
usermod -G "" username

removes all secondary/supplementary groups from username, leaving them as a member of only their primary group. this worked in Solaris 5.9

share|improve this answer
    
Tested in CentOS 6.4; works. –  aggregate1166877 Apr 3 at 12:13
    
Works in Ubuntu 12.04, too. –  aggregate1166877 Apr 3 at 12:22
add comment

You can use the below command

usermod -R "group" "user name"

where "group" is the group that you want to remove the user and "user name" the user that you want to remove from the "group". The above command should be given with out the quotes ex.

usermod -R root imnottheroot
share|improve this answer
1  
What package provides your usermod binary? I'm asking to find out the version, as mine from shadow-utils-4.1.4.3 does not provide the -R option. –  myroslav Oct 17 '13 at 10:42
1  
My shadow 4.1.5.1-5 package (Arch Linux) does have an -R option, but that means something else. It's not Linux I guess. –  Lekensteyn Oct 17 '13 at 14:51
add comment
pw groupmod "groupname|gid" -d "username|uid"

A solution if you are using CSH, for whatever reason.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.