Skip to content
Blog Recover your Linux Root Password

Recover your Linux Root Password

Just follow the below steps to recover it.

1. Reboot your system and at the GRUB press “e”. Edit the first line and make sure it says “linux single”. Then press “b” to boot the new entry line.

2. You will now have access to a BASH prompt. Enter the following commands:


cd /etc
nano passwd

and look for a line somewhere at the top of the file that looks like this:


root:x:0:0:root:/root:/bin/bash

You must remove the “x” from that line so it will look like this:


root::0:0:root:/root:/bin/bash

And save the file.

3. Run the following command:


nano shadow

Edit the first line in the shadow file by removing the encrypted password. The line must now look exactly like this:

root::::

Now save the file.

4. Reboot the system and log in as a normal user, then set your new root password using the following commands:


$ sudo su
$ passwd

courtesy: http://www.geekinterview.com/talk/15727-linux-tips-recover-u-r-root.html

1 thought on “Recover your Linux Root Password”

  1. I would think editing the passwd and shadow file would be a little risky, especially for less experienced users.

    I find it easier to add ‘rw init=/bin/bash’ to the grub command. ‘rw’ to mount the drive in read/write mode, and ‘init=/bin/bash’ immediately fires up a bash shell as the root user for the terminal. Then it’s as simple as entering:

    passwd

    to change the root password. (Note, this completely bypasses any root password that was already set.)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.