Ubuntu Technical

Ubuntu technical problems and solutions reference, a modern cookbook.

Restore lost admin group membership

I found myself recently in the awkward situation of replacing all the groups my user was part of, with a group I wanted to append to.
Due to the fact that I have installed VirtualBox, my user needed to be part of the vboxusers group. All good I thought, so I wanted to add that group to my user.

So I used the following Wrong command

sudo usermod -G vboxusers myuser

As per the help

usermod --help
-G, --groups GROUPS           new list of supplementary GROUPS
-a, --append                  append the user to the supplemental GROUPS

I have realised that I forgot to add the append option. So actually to add the new group to the existing list of groups.
The correct command would have been:

sudo usermod -aG vboxusers myuser

After my reboot, because the effect of the command is not visible until a logout/login is performed, I have found myself without sudo/admin rights. The result of the command:


was myuser and vboxusers. Great, no admin rights.

So here is what I did to solve this problem.

Boot up from the LiveCD. Hope you have one at hand. Doesn’t have to be the latest distribution.

Open the terminal and mount your root:

sudo mount /dev/sda1/mnt
sudo chroot /mnt

Note: instead of sda1 you should use the partition on which your root is mounted. If you are not sure about it, check in Disk Utility application (the default one on your liveCD.

Locate the groups:

cd /mnt/etc

The file which holds the groups is simply called group. But because you have recently changed this file with the wrong command, you need to check the backup file in order to determine which were your old groups, so that you can add them back. The backup file is group-.

Now, you have 2 options to go forward. The first one is to manually edit the group file to add your user against the groups (take the back-up file as an example). The second option is to simply re-add the groups to your user with the usermod command. This way you learn the right format of the command:

usermod -aG group user

Note: there is no need to use sudo in a liveCD session.

Now remove the liveCD and the reboot will make you a happy user 🙂

Thanks to fossfreedom and ccollins

Flattr this


6 responses to “Restore lost admin group membership

  1. Pingback: Restore Admin from Bad Usermod Command | Linux Help Geek

  2. Pingback: Installer une boîte à outils permanente comme un nul(l) 1/6 | Pirater comme un nul(l)

  3. p1l0t September 4, 2013 at 5:15 pm

    It’s group not groups thats why people keep having trouble

    • arzki September 15, 2013 at 1:30 pm

      Could you be more specific? For some, this article was helpful.

      Edit: Yes, now I see that you were talking about the file being called group and not groups. I changed it. Thanks.

  4. Pingback: Ubuntu:Which groups should I normally belong to? – Ubuntu Linux Questions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: