How to remove a user from a group?

Portablejim's answer is accurate but dangerous -- if you typo something, your system may be unusable, especially if you alter the admin group improperly. If you must edit the groups file, use the vipw -g or vigr commands, which verify the syntax before saving. Even then, there are better ways.

From a commandline, the one you probably want to use is the following (as root):

deluser <username> <groupname>

This will remove the specified user from the specified group. You must relogin to see the effect. It will not delete the user, or the group, just the membership. There are also ways of doing it with the usermod command, but it's harder to use as you need to replace the entire list of groups for a user in order to remove a single group. The gpasswd command is also capable of doing this (as sagarchalise points out), but is mostly deprecated. As always, see the man pages for more details.


You can do this:

sudo gpasswd -d username group

See: http://manpages.ubuntu.com/manpages/focal/en/man1/gpasswd.1.html

-d, --delete user Remove the user from the named group.


See zanfur's answer.

Edit the /etc/group file as root (i.e. gksudo gedit /etc/group) and remove the username from the line that starts with 'admin'

i.e.

...
admin:x:120:adminuser,adminuser2,userthatshouldnotbeadmin
...

becomes

...
admin:x:120:adminuser,adminuser2
...

Be warned, typos within the file could break your system.

Tags:

Users