Restore Default Ubuntu Groups.
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.