On Ubuntu 20.04, the root user account is locked by default to enhance system security. While administrative tasks are typically performed using the sudo
command, there are times when direct root access is necessary, such as when recovering from system issues or performing specific administrative tasks that require root privileges. This guide will show you how to change or reset the root password, even if you don't have sudo access.
Resetting the root password from GRUB
If you've forgotten your root password or don't have sudo access, you can reset the root password by modifying the boot process from the GRUB menu. Follow these steps to reset the root password through GRUB.
Step 1: Restart your computer. If the GRUB menu does not appear automatically during boot, press and hold the Shift
key immediately after the BIOS screen to force it to display.
Step 2: In the GRUB menu, highlight the Ubuntu
option and press e
to edit the boot configuration.
Step 3: Find the line that begins with linux
, which is usually the second-to-last line. Look for the terms quiet splash
at the end of this line and replace them with rw init=/bin/bash
. This modification tells the system to boot into a writable shell prompt as the root user instead of the graphical interface.
Step 4: Press F10
to boot with the modified parameters. The system will now boot into a root shell without prompting for a password.
Step 5: At the shell prompt, enter the following command to change the root password. You will be asked to enter a new password and confirm it.
passwd
Step 6: After successfully changing the password, reboot your system by typing reboot
or by pressing the reset button. Your system will boot normally, and you can now log in as root using the new password.
Changing the root password with sudo access
If you have a user account with sudo
privileges, you can set or change the root password directly from the terminal. This method requires that your user is permitted to use the su
command through sudo.
Step 1: Open a terminal and switch to the root user by entering the following command. When prompted, enter your user password.
sudo su
The prompt should now change to indicate that you are operating as the root user.
Step 2: To change the root password, use the passwd
command. You'll be asked to enter a new password for the root account and then confirm it.
passwd
The root password is now set or updated to the new password you provided.
Step 3: To verify that the new password works, exit the root prompt by pressing Ctrl + D
. Then, attempt to log in as root by typing su
and entering the new root password when prompted.
su
You should now be logged in as the root user with the new password, confirming that the password change was successful.
Changing or resetting the root password on Ubuntu 20.04 can be accomplished with or without sudo access, depending on your circumstances. Always use the root account cautiously, as it has unrestricted access to your system and can affect critical components.
Member discussion