How to reset the root password in Debian or Ubuntu

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. You can also reset the root password in the recovery mode.

In order to boot into the recovery mode on Debian or Ubuntu, hold down SHIFT key after powering on your Linux machine. You will then be presented with GRUB menu. Select "recovery menu" option by pressing down arrow key. Do not press ENTER at this point, but rather press "e" key to enter edit mode.

You will see "GRUB" edit screen where you can edit GRUB boot parameters. Move your cursor to the line starting with "linux /boot/vmlinuz-.......", and go to the end of that line. Append "init /bin/bash" right there, as shown below.

Then press Ctrl+X to proceed. 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.

First, find out what the root partition of your system is, by using "fdisk -l" command.

As shown in the screenshot above, the partition marked with "*" under "Boot" column is the root partition of your system (e.g., /dev/sda1).

Remount the root partition as read-write, and finally reset the password, using passwd command.

$ mount -o remount,rw /dev/sda1 /
$ passwd

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

10 thoughts on “How to reset the root password in Debian or Ubuntu

  1. This post is wrong, and fails to understand the fundamental difference between a boot partition, and the root partition. The default partitioning of Ubuntu and Debian happens to have the root and boot partition be the same thing, but if you understand the instructions on the GRUB menu item that you've glazed over, you can see which is the root and which is the boot.

    A proper understanding of what you're doing goes a long way to not borking your system.

  2. The post doesnt say correctly, I think. Generally many but not all installations have a recovery option built-in in boot menu. I tried it, and again it asks for root password to tinker with my OS! By the way, this post also concludes with running the command "passwd'. Why on earth, such a command will not ask for the prevalent password?

  3. aram> system does not ask root to confirm password with passwd command, if you are logged in as root you can change the files in /etc/ so it is less likely to break system using passwd command - it basically respects the fact that you have permission already since you are root.

  4. That's works fine of me.
    I might entered a wrong password-string while Debian Net-Install routine.

    With that tutorial I could correct my mistake.

    Thank you, bro.

  5. Thank you so much! You saved my life, at least it feels that way. I didn't back up my data before monkeying around with changing passwords, which caused me to out fox myself and get screwed. Anyway, your instructions worked perfectly. (Debian, Jessie.)

Leave a comment

Your email address will not be published. Required fields are marked *