How to Rollback Broken Sudo Configuration Ubuntu
Modifying the sudoers file incorrectly can revoke administrative privileges, locking you out of critical system commands. This article outlines the immediate steps to regain access and restore a broken sudo configuration in Ubuntu using recovery mode or a live USB environment.
Understanding the Issue
The sudo configuration is stored in /etc/sudoers. If
this file contains syntax errors, the sudo command will
fail, preventing you from installing software or managing system
settings. Always use the visudo command to edit this file,
as it checks for syntax errors before saving. If you have already saved
a broken configuration, follow the methods below.
Method 1: Using Recovery Mode
If you can access the GRUB menu, this is the fastest method.
Restart your computer and hold the
ShiftorEsckey to enter the GRUB menu.Select Advanced options for Ubuntu.
Choose the kernel version ending with (recovery mode).
In the recovery menu, select root to drop to a root shell prompt.
Remount the filesystem as read-write by running:
mount -o remount,rw /Fix the configuration using visudo:
visudoCorrect the syntax errors or revert recent changes. Save and exit.
Reboot the system.
Method 2: Using a Live USB
If recovery mode is unavailable, use an Ubuntu installation USB.
Boot from the Ubuntu Live USB and select Try Ubuntu.
Open a terminal and identify your main partition using
lsblk.Mount the partition (replace
/dev/sda1with your partition):sudo mount /dev/sda1 /mntEdit the sudoers file directly on the mounted drive:
sudo nano /mnt/etc/sudoersFix the errors or restore the backup file if available:
sudo cp /mnt/etc/sudoers.orig /mnt/etc/sudoersUnmount and reboot:
sudo umount /mnt sudo reboot
Verifying the Fix
Once the system restarts, open a terminal and test sudo access by
running sudo ls. If the command executes without syntax
errors, your configuration has been successfully rolled back.