Ubuntu: Changing groups as nonadmin


Recently, I accidently lowered my privledges on Ubuntu. I was trying to add vboxusers group to my account, and quickly googled to fund out I can add groups by sudo usermod -G vboxusers USER

Unaware this would remove all my groups, I used this command and now I can't use SUDO to change back because I am not an admin.

I already tried logging in as root. it didn't work

This is the only user account on the machine. I need admin privledges. What do I do?


During boot press SHIFT to get into the GRUB menu, then select boot into recovery mode, "Drop to the root shell" and the just re-add yourself to the admin group with usermod including the -a option to append the groups to the current ones:

usermod -a -G admin USER  

Check http://www.psychocats.net/ubuntu/resetpassword for more details for a different case.


Important files like the user and group information are backed up. Once you've gained root privileges (by booting into recovery mode for example), compare the current groups file with the backed up one:

diff -u /var/backup/group.bak /etc/group  

If the only differences are the mistake, overwrite the contents with:

tee /etc/group < /var/backup/group.bak  

Otherwise, manually add yourself to the groups again with:

usermod -a -G admin,group1,group2,... USER  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »