How do I add myself back as a sudo user?
During boot, press and hold the left Shift key, and you should see the GRUB menu.
Select the entry containing (recovery mode) and wait.
You should now be presented with a menu. Select:
remount Remount / read/write and mount all other file systems
and wait for your file systems to get mounted with read/write permissions, then press Enter.
If this option doesn't appear or won't work, you can instead choose the
root
option and use the following command to mount the system partition:mount -o remount /
You can check out which is your system partition with
fsck
command or by viewing/etc/mtab
.After successfully running the mount command (i.e. no error messages), proceed directly to step 5 below.
After choosing the
remount
option, the menu comes up again. Select:root Drop to root shell prompt
Now enter one of the following commands to re-add your user to the
admin
group (for Ubuntu 11.10 and earlier):adduser <USERNAME> admin
or to the
sudo
group (for Ubuntu 12.04 and later):adduser <USERNAME> sudo
Reboot and you should be able to use
sudo
again.
If root login is enabled on your system just drop terminal via Control+Alt+F1 without log in to X. Log in as root and then just add the desired user to admin
group (for Ubuntu 11.10 and earlier):
adduser desired_user_name admin
For Ubuntu 12.04 and later, add the user to the sudo
group:
adduser desired_user_name sudo
If you did not enable root login just choose recovery mode from Grub and then try root shell.
Mount file system as read-write:
mount -o rw,remount /
After that you can again add your desired user to the admin
(or sudo
) group.
I've tried various combinations after doing the same thing as the remount menu option seems not to be in 12.10. I have tried everything else in this post from root. The last was
umount -a
mount -o -w /<path> /
This resulted in the filesystem still being ro due to a setting in fstab to boot ro on filesystem error I think, with it stating it seemed to be ro after mount.
I finally managed it with
mount -o rw,remount /
Although I am not sure how this is different from the previous set of commands.
After applying this variation, adding a user to the admin
(11.10 and ealrier) or sudo
(12.04 and later) group is done the same way:
adduser username admin # 11.10 and earlier
adduser username sudo # 12.04 and later