The root account, sometimes called super user, is the admin account on a Linux system, and is essential for performing all kinds of administrative tasks. You’ll need access to it in order to install or remove packages, manage other user accounts, and a lot more things. Anytime you access the root account, either through the
sudo commands, you’ll be prompted for the root password.
If you have forgotten the password to your system’s root account, you don’t necessarily have to go back to square one and reinstall the whole operating system. It’s possible to recover and reset the root password, even without the old password. In this guide, we’ll take you through the step by step instructions of recovering a forgotten root password on Linux. This will work regardless of the Linux distribution you’re running, as long as its using the GRUB bootloader. Other bootloaders will have similar instructions.
In this tutorial you will learn:
- How to reset a forgotten root password on Linux
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Recover forgotten root password
Follow along with the steps below to reset your root password by entering GRUB recovery mode. In the screenshots below, we are using Ubuntu Linux for an example, but the instructions will apply to any distro. In some cases, you may have to adapt them a little.
- First thing you’ll need to do is reboot the machine and access the GRUB menu. This can be done by holding down the
Shiftkey as the computer is first booting up. Once the menu appears, use your arrow keys to highlight the “Advanced options” selection. On some distros, it may just say the usual name of the operating system, such as “Fedora Workstation”.
- Next, press
eon your keyboard to edit the commands.
- Using your arrow keys once again, scroll down a bit until you see a line that begins with
linux /boot/vmlinuz.... We will need to make some small changes to this line. Use the screenshot below for reference so you can make sure you’ve found the correct line.
- The last part of this line is
ro quiet splash $vt_handoff. We will need to replace this text with the following line. Make sure to first backspace the current settings, then type these new ones. Note that on some distros, the line may be a little different, but should definitely include the
ro(read only) text, which needs to be replaced.
This will give us write permissions as well as a bash shell, so we can use the usual Linux commands to change the root password.
- Once you have made these changes, press the
F10key to save the changes and reboot your system. You will be brought back into a bash prompt, but only on this first reboot. Subsequent machine boots will be back to normal.
- Your root partition should be automatically mounted, with read and write permissions. You can verify this by executing the
mountcommand. If it’s not already mounted, use the following command below to mount it.
# mount -n -o remount,rw /
- Now, simply use the usual
passwdcommand to set a new root password.
- When done, we just need to reboot the system. The usual
shutdowncommands will not work. Instead, execute the following command to reboot the system and load into the operating system like usual.
# exec /sbin/init
That’s all there is to it. Your computer should boot up like normal, and you will be able to login to the root account (or use commands with sudo) while specifying the password you just set.
In this guide, we saw how to reset the root password on a Linux system, even if the original has been forgotten. Although it sounds complicated, this is a relatively simple task that GRUB can facilitate by allowing us to mount the root partition without loading into the operating system.