Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I added a user account to the admin group and discovered I added wrong user. So I now have to remove the account from the admin group.

How can I remove an account from a group without deleting the user?

share|improve this question
add comment

4 Answers 4

up vote 42 down vote accepted

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.

share|improve this answer
1  
gpasswd is not deprecated. Its entire purpose is to administer /etc/group and /etc/gshadow. Also, while your method does work, and is mentioned in the deluser man page, it's a bit risky. If you accidentally hit enter before you type the group name, you've remove the user. Better hope you remember its UID so you can add it back quickly. It would be safer to use gpasswd which is designed for this purpose. –  Starfish Jul 27 '13 at 23:53
    
I thought about this risk too. I guess you can always start such a command with a '#', hit enter, and then rerun it while just removing the first character. –  eze Dec 6 '13 at 23:47
add comment

I think you can do this

sudo gpasswd -d username group

or you can view the manual of gpasswd

share|improve this answer
add comment

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
...
share|improve this answer
4  
Please don't advice to edit these system files manually. In case you screw up your system might become inaccessible. –  gertvdijk Dec 4 '12 at 16:28
    
Or at least back them up first. (Related information.) –  Eliah Kagan Jan 11 '13 at 0:53
1  
I think you should post this as it is valuable insight into how Linux works. However, should include a warning that there is a much safer way –  Freedom_Ben Jan 9 at 1:37
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

BR

share|improve this answer
3  
No, on Ubuntu "-R" does not remove a user from a group. It applies the usermod changes to the CHROOT_DIR. See the documentation. –  S.L. Barth Mar 27 at 14:35
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.