1. Fix remove of last sudoer
1.1. Symtom
You cannot login as root anymore on an Ubuntu based linux system
1.2. Cause
You removed the last sudoer, just like the Dodo
1.3. Solutions
-
Starting with Shift pressed in Linux Mint fails since using that will just bring up the Linux Mint screen
-
Starting with Esc pressed during boot will enter a MINIMAL BASH (grub) environment where you do not want to work in
-
Create a bootable USB-stick using the links below
-
Note self: Use my USB-stick nr. 2 in my archive (drawing-box, Dutch: tekendoos)
-
-
Boot with that stick
-
When Linux Mint is started, open a terminal
$ fdisk -l
...
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 1000214527 999163904 476,4G Linux filesystem
...
$ mkdir /media/rescue
$ mount /dev/nvme0n1p2 /media/rescue
$ cd /media/rescue
$ chroot /media/rescue vim sudoers
-
Below user aliases add this which might be brute but at least that works
-
<user> ALL=(ALL) NOPASSWD:ALL
-
Reboot and you are back into business!
$ sudo usermod -aG <groupName(s)> <userId>
e.g.
$ sudo usermod -aG adm,cdrom,dip,plugdev,lpadmin,sambashare,docker,finance jdoe
| Add the -a flag above!!! |
| The groups above should be separated with a KOMMA without SPACES |
$ mkdir /media/rescue
$ mount /dev/nvme0n1p2 /media/rescue
$ cd /media/rescue
$ chroot /media/rescue usermod -aG sudo <user>
| I did not test the alternative method above |
1.4. Resources
1.5. Follow ups
Add the user to all groups which he/she was member of in the past, e.g. the group docker using
$ sudo useradd -aG docker <user>
$ sudo adduser <backupUsername>
$ sudo usermod -aG sudo <backupUsername>
| After adding the user to the group, you might have to relogin or reboot the machine or use this link ⇒ https://superuser.com/questions/272061/reload-a-linux-users-group-assignments-without-logging-out |