Commands.page Logo

How to Recover Sudo Access on Ubuntu Without Privileges

Losing sudo access on Ubuntu prevents system administration, but you can restore it using recovery mode. This guide explains how to boot into the root shell, remount the filesystem, and assign sudo privileges to your user account directly.

Access the GRUB Menu

Restart your computer. As soon as the BIOS or manufacturer logo disappears, press and hold the Shift key. On some systems, you may need to press the Esc key repeatedly. This action will interrupt the normal boot process and display the GRUB boot menu.

Enter Recovery Mode

Use the arrow keys to select Advanced options for Ubuntu and press Enter. From the list of kernels, choose the line that ends with (recovery mode) and press Enter. The system will load a recovery menu.

Drop to Root Shell

In the recovery menu, navigate down to root (Drop to root shell prompt) and press Enter. You will be taken to a command line interface at the bottom of the screen. Note that the filesystem is mounted as read-only by default.

Remount the Filesystem

To make changes to system files, you must remount the filesystem with write permissions. Type the following command and press Enter:

mount -o remount,rw /

Restore Sudo Privileges

Identify your username. If you are unsure, type ls /home to see the available user directories. Once you have your username, add it to the sudo group using the following command, replacing yourusername with your actual account name:

usermod -aG sudo yourusername

Reboot the System

After executing the command, type reboot and press Enter to restart your computer normally. Once logged in, your user account will possess sudo access, allowing you to execute administrative commands using sudo.