Regain Sudo rights after removing from admin group [duplicate]

Solution 1:

Hmm well you've covered what I would have suggested first. Seems annoying that Rescue mode would hassle you for a password if the entire disk weren't encrypted (I don't know, that might be standard protocol).

I'd personally jump into a live environment (via Live CD or Live USB), mount the filesystem (assuming it isn't encrypted) and edit its etc/group file and add yourself back in. The resulting line should look something like this (though the GID may be different):

admin:x:115:oli

Or on Ubuntu 12.04, find the line for the sudo group instead of the admin group.


Alternatively, you can probably chroot from the LiveCD to run commands. (sudo password for the LiveCD is a blank password, just press return when prompted)

sudo mount /dev/sdYY /mnt  # change sdYY to your root partition
sudo mount --bind /dev  /mnt/dev
sudo mount --bind /dev/pts  /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys  /mnt/sys
sudo chroot /mnt
sudo adduser your-username admin

For Ubuntu 12.04 and later, add the user to the sudo group instead of the admin group:

sudo adduser your-username sudo

chroot drops you off at a root shell inside your filesystem so should let you do fancy things like adding users to groups. It's most useful for fixing boot issues but it can do a lot of gubbins.

Solution 2:

At the grub boot-up menu, press e to edit the kernel launch command-line and append the word single at its end. This should boot the system on single-user mode (as root) and allow you to perform any modifications.