jump to navigation

Restore Default Ubuntu Groups. July 2, 2007

Posted by ccollins in Linux, Open Source, Ubuntu.
trackback

While this affected me on Ubuntu, I guess it’s possible that other Linux distros will also be affected. Though the incorrect use of usermod, I managed to screw up my groups configuration leaving me without sudo or su ability, which is obviously important on Ubuntu to make system configuration changes. Read on for the whole story of how I recovered, and restored correct groups again.

One of the libraries I’m using required me to be a member of the uucp group for it to work, so off I went and read the manpage of usermod so I could add myself to that group. Two shakes of a lambs tail later I had issued a:

sudo usermod -G uucp ccollins

This was quite effective at adding me to the uucp group, but had the unfortunate side effect of removing me from all the other groups I was a member of. To top it all off, not being a member of admin anymore, I could no longer use sudo or su, and was effectively unable to recover.

What I should have done, was issue usermod as:

sudo usermod -a -G uucp ccollins

This would have the effect of appending the group to my list, rather than replacing.

So, to recover I had to use the Ubuntu live CD. I booted Ubuntu from the live CD and when I logged in I was able to mount my root partition (/). Once this was done, I could manually edit the /etc/group file and add myself to the admin group. A quick reboot later and I was able to use sudo and su again, and add myself to all the other groups I’d lost.

sudo usermod -G ccollins,adm,uucp,dialout,cdrom, \
floppy,audio,dip,video,plugdev,scanner,netdev, \
lpadmin,powerdev,admin ccollins

sudo usermod -g ccollins ccollins

This restored my group memberships, and restored my initial group to ccollins. All I needed to do now, was log out and log in.

AddThis Social Bookmark Button

Comments»

1. adamjcollege - August 2, 2007

Woohoo. This was a lifesaver!

2. Linux Blog - linux.dsplabs.com.au » Blog Archive » No volume control GStreamer ... found — no sound on Ubuntu - December 20, 2007

[...] Important, make sure the -a switch is used, otherwise the user kamil will be a member of the audio group only! If that happens you will have to restore the original group permissions as discussed by ccollins in this post. [...]

3. Molgor - January 15, 2008

Thanx a lot!! It was difficult for me to remmeber what was the fu@%! problem. Later on I realized that I missunderstand the usermod shit just like you.
Maybe the activation of the root login isn’t a bad idea after all.

Aknowledges from México.

4. Mahesh - January 19, 2008

Wow! Your quick little note was a life saver for me too.

I was trying out some Ubuntu admin stuff and wrongly used the usermod command “exactly” like you did. But, I did so because the book I was referring to told me to do so!! (WTF!! I know!)

Anyway, once that was done, I reboot the system into recovery mode (single user mode through Grub) and added a root passwd. So, then on I could use “su -” to become root, but, otherwise I felt pretty helpless since I couldn’t work with sudo.

I am now going to restore my admin privileges as per your note and hopefully things will work well.

Thanks for encountering the problem, finding the solution, and most improtantly posting it for public use. Great job.

5. ghost - January 26, 2008

Dude, Duuuuuude!!! thanks alot man,this helped me alot, and i learned something new in the process. Thanks for sharing it ;)

6. bartman - February 20, 2008

This is a complete lifesaver. A few things that would’ve saved me quite a bit of time:
* if the user calling “$ sudo …” isn’t in the group admin, the command won’t execute but the user won’t be notified. You have to use $ su and log in as root.
* the changes take effect as soon the user whose groups are changed logs in the next time. A reboot isn’t necessary!

7. someone - February 26, 2008

thank you! I’ve done that mistake with usermod too!

8. Jman - March 15, 2008

Another thanks over here… you fixed me!

9. Oggle - March 26, 2008

you have no idea how much this just helped. Thank you so much!

10. Nomad - April 20, 2008

Thanx. It’s the clearest explanation I’ve found.
And it’s really helped

11. Patrick - July 6, 2008

Wow! Thank you for this. I had completely forgotten and it was driving me nuts as the CLI kept spitting back error reports with Usage instructions…. of which were not very helpful. But this post was.

A quick note at the risk of sounding pretentious, it’s best to experiment your system administration tasks on guest accounts or accounts that wouldn’t affect you if you messed them up. I’ve been toying with a bunch of advanced configuration lately, like everyone here… but when I do I make absolutely sure I’m playing with the guest account.

Cheers

12. ccollins - July 7, 2008

Hi Patrick,
That’s true. When it comes to Linux and Unix type systems, it pays to be paranoid :-)

-Chris

13. ccollins - July 15, 2008

Jason over at Ubuntu Forums suggests an even easier fix for messed up groups. Reboot into the recovery console and execute “adduser YOUR_USERNAME_HERE admin”. That gets you back on the admin group, and allows you to recover your other groups also.

Full post is here:
http://ubuntuforums.org/showpost.php?p=4273283&postcount=2

14. bblackmoor - September 12, 2008

Great tip, here. Thanks.

15. bblackmoor - September 12, 2008

I should add that not having a “root” in Ubuntu really floored me. Fortunately, I have physical access to the machine, other wise my omission of the -a would have been a catastrophe.

Live and learn.

16. dirtycutmaster - November 5, 2008

Just to say as Oggle did – you don’t have any idea how much that helped me! Thanks a thousand times!

17. Ricky - November 12, 2008

It saved my bacon, and it was EXACTLY the same thing, but my evil group was sbox.

Thank you.

18. Sektor - November 17, 2008

Same problem here, this article was a life saver. Perhaps the man pages should include some kind of warning, as this seems to happen a lot.

Thanks.

19. Nic - December 15, 2008

Many thanks – I messed up in exactly the same way. Very handy to have a list of default group memberships out there.

20. ray - February 7, 2009

Unreal. U saved my life! I was studying for LPI and the text book told me to run the command: sudo usermod -G sales bob. Next time I booted up I couldn’t log in, system couldn’t find my home folder, I couldn’t access my home folder, all thiseven though I still owned it. Nightmare.

I think I love you.

lol

21. r - February 25, 2009

If you don’t have a live CD your can edit the grub menu line : add “init=/bin/bash” and boot.
You then have access to a bash terminal with no need for password or root right.
You must remount your partition with write rights:
mount -o remount,rw /
then edit /etc/group to add sudo right to your user.
reboot and you are done

22. Thijs - May 5, 2009

Great!

23. Allan Registos - May 26, 2009

There is a quick solution w/o having to boot from a live CD.
But a requirement is that you must have an existing webmin installed. I don’t know that this will going to everyone but at least it works for me. The reason why I said this because I am currently logged at the webmin web interface. I don’t know if you can still log in at the webmin once you messed with your admin group.

I am a user of Ubuntu for over a year but I still messed the admin group and still don’t know that the group is critical to the Ubuntu system. I deleted it via webmin, since I want to create a user admin for that purpose. Now when I go to the CLI to install software, the error says I am not belong to the sudoers file.

The thing is I am currently logged at the webmin interface. I simply re-created the group admin. I put my username on that group and try to access the synaptic again without error. I can now use the CLI and install programs.

24. Boris - June 20, 2009

Thanks a lot! Very helpful…

25. ganapathi - August 9, 2009

Thanks a lot!! It helped me too

26. Jim McLaren - October 9, 2009

You don’t actually need to use a live CD. When grub starts, hit escape to bring up the boot menu, and select ‘recovery mode’. When in recovery mode, select the option to drop to a root prompt. Then type in the command:

adduser <username> admin

where <username> is the account you want to add to the admin group.

Reboot, and you should be able to add yourself to other groups from a terminal on the desktop.

ccollins - October 9, 2009

Thanks Jim,
The operations of the recovery console are not something I know a lot about. Thanks for the tip! You learn something new every day :-)

-Chris