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

Non-compliant solution (false positive)
  • 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

  • Link to the false positive

  • This is what happened to me

Compliant solution
  • 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

Invoke fdisk -l
$ 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
...
Compliant solution (continued)
$ mkdir /media/rescue
$ mount /dev/nvme0n1p2 /media/rescue
$ cd /media/rescue
$ chroot /media/rescue vim sudoers
Modify the sudoers file
  • 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!

Add your user to the groups you belonged to
$ 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
Alternative method (not tested yet)
$ 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.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>
Create a backup sudo 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