Accidently Removed Myself From Sudoers!

I’ve used Linux for years, primarily Ubuntu Desktop and Server. Recently I had been purchasing computer parts, anticipating the building of my next computer. Last Monday I put it all together, and started in on loading my operating system of choice, Ubuntu 14.04. Moving forward, I then started installing the essential programs that I use. I really didn’t run into any problems, until I made a stupid mistake while adding myself to a group.

I was adding myself to apache’s www-data group using usermod, and made a big mistake. I forgot to add the -a option, which made usermod put me in the www-data group, but removed me from all other groups! This is not the end of the world, right? There are tutorials all over the internet on Fixing Sudo, and a search for “accidentally removed myself as sudoer” yields many results. The problem was, nothing I could find would actually work.

Note: I should have used the following command syntax:
sudo usermod -a -G groupName userName

Recovery Mode

Ubuntu Recovery Mode is where you can add yourself back as a sudoer, but everything I could find online said to hold down the shift key to access recovery mode while booting. It didn’t work. I tried like 10 times.

Mounting via Live CD + Chroot

There are a few articles online that mention using a live CD then mounting /dev/sda1, then chrooting it, then blah blah blah. I didn’t work. By this point I was wondering if I was going to have to reinstall the whole OS and all the programs. As a last resort (which is probably what I should have done first), I asked a question over at the Ubuntu Forums, and within minutes had my answer.

Use Esc Not Shift

In order to gain access to the Recovery Mode, I needed to press the Esc key, not the Shift key. This is because my computer is using EFI to boot. After gaining access, the tutorials that mention recovery mode worked. I simply used “Drop to root shell prompt”, run mount -o remount,rw /, then used usermod to add myself back to all of the default groups.