How to reset the root password in Debian or Ubuntu

Last updated on September 16, 2020 by Dan Nanni

If you forgot the root password for your Debian system, do not panic. There is an easy way to reset the password. Linux provides a special mode called recovery mode or single user mode, whereby a Linux host boots into a single user environment where you get to access shared resources such as file systems exclusively. The recovery mode is often used when you need to perform file system maintenance and recovery, or conduct security vulnerability auditing in an isolated environment. It also allows you to reset the root password. Read on to find out how to reset the root password using the recovery mode on Debian or Ubuntu.

In order to boot into the recovery mode on Debian or Ubuntu, hold down LEFT-SHIFT key right after powering on your Linux machine. You will then be presented with GRUB menu. Select Advanced options by pressing DOWN arrow key and press ENTER.

On the next screen, choose recovery mode for the default boot (5.4.0-42-generic in this example) and press ENTER. Then you will be entering the recovery mode.

In the recovery menu, choose Drop to root shell prompt option.

After all subsequent booting sequence is over, you will finally get a root prompt. In the recovery mode, the root partition is mounted as read-only by default, and so you cannot change the root password as is. In order to be able to reset the root password, you need to re-mount the root partition as read-write.

To do that, first find out the root partition of your Linux system by using df command. In the output of df, the partition that is mounted on / is your root partition, and thus holds the root filesystem, where the root password is stored.

The above screenshot indicates that the root partition is /dev/sda5 in this example. Remount this partition as read-write, and finally reset the password using passwd command.

# mount -o remount,rw /dev/sda5
# passwd

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean