15

I'm using Ubuntu 11.10 and I installed VirtualBox.

This required me to add myself to the vboxusers group but when I add myself to vboxusers group I am no longer be in other groups and especially admins group!

When I add myself back to admins group I no longer be am in the vboxusers group !

Commands that I used

  • to add user to "vboxusers": usermod -G vboxusers myusername

  • to add user back to admins group in single user mod: usermod -aG admin myusername

2
  • @Caesium Thank u. Thanks all :) Solved by following Caesium's solution :D
    – R9TySix
    Feb 15, 2012 at 17:05
  • Then you should fix the accepted answer, currently a non-working solution is accepted which will confuse future visitors.
    – Caesium
    Feb 15, 2012 at 17:31

6 Answers 6

19

Your second command is right.

By default, usermod -G replaces all supplementary groups the user is in (the primary group is generally named the same as your username, and specified separately; don't mess with that though). By also using -a it appends the groups you give.

So this should work (and does, for me, just tried it):

usermod -aG vboxusers myusername

If running that command takes you out of any other group then you've found a bug. Note you have to relogin to see the effects.

1
  • 2
    i am getting error: usermod: group 'vboxusers' does not exist
    – Alex Jones
    Dec 29, 2014 at 14:43
4

Alternatively:

gpasswd --add myusername vboxusers
4

According to the usermod man page the correct command to add a user to a group is

sudo usermod -G group -a username

or in your case since you want to add your self to the vboxusers group that will be

sudo usermod -G vboxusers -a $USER
1
  • Exactly equivalent to -aG group (assuming usermod knows how to parse args)
    – Caesium
    Feb 15, 2012 at 16:56
1

Never use the top method to add a user to vboxusers by using the usermod -G vboxusers myusername command. This will make you lose your sudo privileges!

If you have lost your sudo privileges, you can use the method described here to recover them. It boils down to executing the following command:

usermod -G adm,cdrom,sudo,dip,plugdev,lpadmin,guoshicheng,vboxusers myusername
3
  • 1
    Welcome to Ask Ubuntu! The question's author already used the command you're telling him not to use. He has also already accepted a solution for his problem. There is actually no point in anwering the question again. And linking to a site in Chinese is also not very helpful on an English site.
    – bender
    Jan 23, 2013 at 23:45
  • @bender Actually there is a point if the answer is valid and on topic. Accepting answer means that it worked for the OP. Please read the about page.
    – Symin
    Jan 24, 2013 at 0:17
  • @Symin: Nevertheless, the question's author already used this command. Strictly seen, this is already not an answer to the question. The accepted answer already describes in detail what has been done wrong and why, this answer adds (almost) no new information. And describing (once again) how to get back lost privileges has been done many many many times on this site. And just for the sake of completeness, this command won't work any more after sudo privileges were lost (unless one hasn't logged off yet or still has an open root shell).
    – bender
    Jan 24, 2013 at 0:49
0

What you want to do is just open the terminal and vi /etc/group then add of replace vboxusers:x:128:uname (uname of the account), save and log out. Just login and open VirtualBox, Settings -> USB -> Add filter from device. I think it will work.

-1

To add a user to multiple groups use the following command is executed with commas seperating each group for example: admin,vboxusers

useradd -G admin,vboxusers myusername

2
  • That will add a new user and make the user belong only to those groups. Feb 15, 2012 at 16:35
  • 2
    If that's so, then Oli's answer is wrong too?
    – Caesium
    Feb 15, 2012 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .