Ubuntu – Regain Sudo rights after removing from admin group

rootsudo

I accidentally removed myself from the admin group when editing the user. Now I can no longer use sudo. The error says: ber is not in the sudoers file. This incident will be reported.

I booted up in rescue mode, but, when going into root prompt, it asks me for the root password. I don't have one, and providing with my own (first and only ubuntu-user) password, it won't allow entrance.

My harddisk is encrypted, but only the /home/user part, not the entire disk, afaik.

What can I do?

Best Answer

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.

Related Question