Commands.page Logo

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.

  1. Restart your computer and hold the Shift or Esc key to enter the GRUB menu.

  2. Select Advanced options for Ubuntu.

  3. Choose the kernel version ending with (recovery mode).

  4. In the recovery menu, select root to drop to a root shell prompt.

  5. Remount the filesystem as read-write by running:

    mount -o remount,rw /
  6. Fix the configuration using visudo:

    visudo
  7. Correct the syntax errors or revert recent changes. Save and exit.

  8. Reboot the system.

Method 2: Using a Live USB

If recovery mode is unavailable, use an Ubuntu installation USB.

  1. Boot from the Ubuntu Live USB and select Try Ubuntu.

  2. Open a terminal and identify your main partition using lsblk.

  3. Mount the partition (replace /dev/sda1 with your partition):

    sudo mount /dev/sda1 /mnt
  4. Edit the sudoers file directly on the mounted drive:

    sudo nano /mnt/etc/sudoers
  5. Fix the errors or restore the backup file if available:

    sudo cp /mnt/etc/sudoers.orig /mnt/etc/sudoers
  6. Unmount 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.