In Linux, regular users and superusers are allowed to access services via password authentication. In the case a regular user can’t remember their password, a superuser can reset the password of a regular user right from the terminal. However, what if the root user loses their password? This article takes a look at how to recover a lost root password in Linux using four different methods.
Note: while the following will work on most Linux systems, it’s important to keep in mind that some distros, such as Ubuntu, disable the root user by default. For those, you can access the root shell by running sudo -s
.
Reset the Root Password using Sudo
The easiest way to reset the root password is by taking advantage of a regular user that’s a currently a member of the “sudo” user group. To check whether your current user is a sudoer, use the groups
command.

Note: some distros will use the group “wheel” to indicate that the current user is part of sudoers.
Once you determine that the current user can use sudo, run the following command:
sudo passwd root
Provide the new password for your root user, then type it again to confirm it.

Test whether your new root password is working properly by running su
.

Good to know: learn how to manage user passwords in Linux today.
Reset the Root Password Using GRUB
Apart from sudo, you can also reset the root password of your Linux system through the GRUB bootloader. This is useful if you don’t have a sudo-capable user to perform a password change from the terminal. To do this, you need to force the machine to boot in “single user mode” which automatically loads a workable root shell.
Start by rebooting your Linux system, then press the Down Arrow to prevent the machine from booting past the GRUB menu.

Press E on the GRUB menu to make a temporary change on the system’s boot script.
You need to modify it or change it from “read-only” mode to “read-write” mode. Find the line beginning with “linux.” Look for ro
and change it to rw
. Add init=/bin/bash
at the end of the line.

Press F10, then select the first entry in the bootloader menu. This will display a screen with a prompt.

Mount your root file system in read-write mode:
mount -n -o remount,rw /
You can now reset your lost root password by using the following command:
passwd root

Once done, run the following command to exit the prompt and boot into your computer:
exec /sbin/init
On a side note: interested in learning more about bootloaders? Check out our article where we compared GRUB with Systemd-boot.
Reset the Root Password using Systemd Debug
On top of using the GRUB bootloader, it’s also possible to use the Systemd Debug mode to reset your system’s root password. Begin by opening the GRUB configuration file using your favorite text editor:
sudo nano /etc/default/grub
Look for the line that contains “GRUB_CMDLINE_LINUX,” then add the following inside its quotation marks:
systemd.debug-shell

Save your GRUB config file, then recreate the GRUB setup for your system:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Reboot your system, then wait until you reach your machine’s login prompt.
Press Ctrl + Alt + F9 to boot into the debug root shell.

Run passwd
on your debug root shell. This will bring up a prompt where you can type and confirm your new root password.

Confirm that it’s working properly by going into a different TTY and logging in as the root user. For example, pressing Ctrl + Alt + F2 will move your session to an unused TTY in your system.

Note: the Systemd Debug mode will persist until you remove the “systemd.debug-shell” value in the GRUB config file and remade the GRUB setup for your system.
Reset the Root Password Using a Live ISO
If you have a Linux Live ISO, you can also boot into it and use it to reset the root password. Start by downloading the latest version of Ubuntu, and create a bootable drive from it.
Boot the removable drive instead of your hard drive. You can do this by going into your system’s BIOS and setting the boot priority to your removable drive.
On the display screen, select Try Ubuntu. This will bring you to the Live desktop.

Open the terminal and type the following command to become root:
sudo -s
Find the location of the root partition of your hard disk using the following command:
fdisk -l
In most cases, it will either be “/dev/sda4” or “/dev/vda4,” although it can differ depending on how your hard disk is partitioned.
Mount the hard disk partition of the system to be recovered using the following command:
mkdir /mnt/recover
mount /dev/vda4 /mnt/recover

At this point, we need to jail ourselves in the “/mnt/recover” directory. This means that we are pretending to be on the regular Linux filesystem. This is simply known as chrooting.
chroot /mnt/recover
Use the following command to reset your Linux root password:
passwd root

Once completed, exit from the chroot shell:
exit
Unmount the root partition and exit your root:
umount /mnt/recover
exit
Lastly, remove the Live CD and reboot into your Linux system.

Learning how to change the root password in Linux is just the one part of keeping your machine in tip-top shape. Explore how you can further protect your system from malicious actors by encrypting your hard disk today.
Image credit: Grok via x.ai. All alterations and screenshots by Ramces Red.
7 comments
Thank you, very handy article.
“2. Reset Lost Root Password Using Live CD”
I assume that could be ANY LiveCD? Does not have to be Ubuntu.
I also assume that a USB stick can be used.
Thanks but I didn’t manage to reset the password (tried both ways).
The whole process worked fine but when I try to login with the new password the display turn black for a second and then the login screen appears again (no wrong password message)
Any suggestions?
If you don’t get a message telling you that the authentication failed it’s much more likely a system issue. Linux seems to be logging you in fine but something isn’t able to get you into the shell for some reason or another. Corrupt bash/zsh/fish shell maybe? Have you tried installing your OS over your current installation without reformatting using a live environment?
I’m not sure what else to do if you can’t query the system due to not being able to enter the shell. Normally I would just grab my Arch Linux thumbdrive and try to chroot into the Linux partition. I’d be happy to work with you more on this problem but by now I’m not sure how helpful I can be.
The first solution worked for me. Thank you for this!
Thanks! It’s very helpful, clear and elaborated
In the past few months I have successfully reset my root password a couple of times using the GRUB method. Thanks, Ramces.