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

7 Answers 7

up vote 91 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
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
Doesn't work for me. I get two messages: a) Removing user from group. b) gpasswd: user is not a member of group. Afterwards running "members group" shows no change. –  geoidesic Dec 15 '14 at 7:19

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 -s
share|improve this answer
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
Alternatively, after modifying /etc/group run grpconv to update /etc/gshadow rather than editing it. –  Cyrille Oct 20 '14 at 12:57
sudo deluser jenkins admin /usr/sbin/deluser: You may not remove the user from their primary group. –  Jonathan Leaders Oct 20 '14 at 17:16
@JonathanLeaders Every user needs to be in at least one group. Use usermod or vipw to change the user's primary group. This question was about supplementary groups. –  Gilles Oct 21 '14 at 16:44
Nice. There's also the simpler adduser $user $group command instead of the usermod -x -y -z -.... –  LonelyPixel Dec 11 '14 at 12:35
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 '14 at 12:13
Works in Ubuntu 12.04, too. –  aggregate1166877 Apr 3 '14 at 12:22

You can use the below command on SUSE distributions.

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
What package provides your usermod binary? I'm asking to find out the version, as mine from shadow-utils- does not provide the -R option. –  myroslav Oct 17 '13 at 10:42
My shadow 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
I'm not sure this will work. The manpage is saying that -R is: "-R, --root CHROOT_DIR Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. " –  MikeKusold Jul 8 '14 at 23:34
The only things sort of related I could find was this oracle manpage, but that's still not about the same thing, so this answer should maybe be removed. –  kyrias Oct 5 '14 at 22:03
sudo usermod -R admin jenkins usermod: invalid chroot path 'admin' –  Jonathan Leaders Oct 20 '14 at 17:18

this is the old school approach...

most nix systems maintain group information into a plain textfile /etc/group, where group members are included within the group line entry, delimited by the :* character.

now suppose you want to remove a user named myuser from a group mygroup, start by backing up /etc/group, then use the editor of your preference to edit under su privileges file /etc/group and remove the myuser reference from the mygroup line entry, eg:

original line is something like this:


after editing should be left like this:


Whichever method you will follow, remember to reboot before changes will be applied.

share|improve this answer
vigr was already mentioned for editing /etc/group manually. My manual pages says that user names are separated by commas, not by colons. Rebooting is not necessary, you just need to re-login (or use newgrp). –  Lekensteyn Dec 10 '14 at 16:24

username: abc2 group name: newgroup11

Task: Removing user from group

[root@home1 ~]# groups abc2
abc2 : abc2
[root@home1 ~]# usermod -G newgroup11 abc2
[root@home1 ~]# groups abc2
abc2 : abc2 newgroup11
[root@home1 ~]# usermod -G newgroup11 abc2
[root@home1 ~]# usermod -G abc2 abc2
[root@home1 ~]# groups abc2
abc2 : abc2

** Kindly correct me if i am wrong **

share|improve this answer
This "works", but only because you have a single secondary group. usermod -G newgroup11 abc2 will put you in the secondary group newgroup11. Since the primary group is abc2, you will end up in both groups. usermod -g abc2 abc2 results in newgroup11 being removed from the secondary groups because it is not mentioned anymore. So for three or more different groups, this method won't work. See the other answers involving gpasswd for a better command. –  Lekensteyn Jan 17 at 22:56
pw groupmod "groupname|gid" -d "username|uid"

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

share|improve this answer

Your Answer


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.