Recover lost root password

The scenarios may differ but we all have and will(may be) face problems whose solutions are related to the recovery of lost root passwords. I used to face this problem a lot of times and after trying out a lot of different methods I finally came up this article. So, here are a few tips and methods which can help you to recover or change root passwords in different situations.

From the Grub or Grub2

Once you are on the grub menu, press 'e' to edit the menu entries and scroll to the line starting with kernel or linux depending on whether it is grub legacy or grub2 respectively, add "single" at the end and hit enter to save it. The final edited line should look something like this.

linux   /boot/vmlinuz-2.6.31-14-generic root=UUID=b8080487-b557-4f55-b288-d7ef2c2b9cc1 ro   quiet splash single

P.S. - The first word would be kernel in place of linux if you are using grub legacy.

Now, boot from your edited boot entry and you will be dropped to a shell as root. This is more or less similar to the recovery mode option we see now a days in modern distros. But if you are prompted for a root password (which is mandatory in some systems if you are trying to boot into a single user mode) then you may want to try adding "init=/bin/bash" at the end of the line instead of single. So, the boot entry will look something like this.

linux   /boot/vmlinuz-2.6.31-14-generic root=UUID=b8080487-b557-4f55-b288-d7ef2c2b9cc1 ro   quiet splash init=/bin/bash

This will boot into a very basic system, using the bash shell instead of init. After you are dropped to the bash shell, you may have to mount the root partition read-write. If you know the root partition then run this command to mount it.

$ mount   -o remount,rw  /

After that you can change the password using the passwd command.

[root]$ passwd

But what if you are unable to edit the grub menu because grub is password protected. Don't worry, the best part of being a linuxer, there is always way out of everything. Read on!!

Using LiveCD

So, we are here because the Grub is locked. Boot into the live user mode and mount the root partition. If you don't know the root partition then run this command to get a list of diff. partitions on your disk.

[root]$ fdisk -l

Now, find your root partition and mount it. Lets assume that your root partition is /dev/hda1 and run the following command.

[root]$ mount -o,rw /dev/hda1 /mnt

You may check if its the right partition by listing the files in /mnt directory (plz. don't ask, how to do that). Now, chroot mnt directory and change the password.

[root]$ chroot /mnt

[root]$ passwd

Happy now!! But what if the computer has a BIOS level protection ie. you can't boot a Live CD or USB. In such cases its better to consult the BIOS vendor for the solution. 

5 Comments

Unix Monkey (not verified)
November 29th, 2009 12:05 am
BIOS level protection is not so high level security it can be broken easily by removing the CMOS battery and if you are still hungry see here http://www.biosman.com/bios-password.htm Good work - Nice posts - very informative - keep rocking :-)
Anon Linuxer (not verified)
August 20th, 2010 12:23 pm
I am accomplishing analysis plan in the acreage of solar energybathroom vanity,mosaic glass,bamboo furniture,bamboo kitchenI charge digital abstracts of all-around solar radiation of Nepal. If accessible amuse accommodate us for added analysis or informations.
Anon Linuxer (not verified)
August 20th, 2010 12:25 pm
I am accomplishing analysis plan in the acreage of solar energy. I charge digital abstracts of all-around solar radiation of Nepal. If accessible amuse accommodate us for added analysis or informations.
Gwen Petitte (not verified)
August 20th, 2010 12:27 pm
The first step when you write from what you read is to be sure you understand what you have readhttp://www.haoxinglass.com To ensure your understanding, you should be an active reader. This means that you should read more than once with a different purpose each timehttp://www.china-bambooflooring.com you should ask questions beforehttp://www.hc-cca.com during, and after you read, and you should make notes as you read.
ESET (not verified)
October 29th, 2010 06:30 pm
but i think bios is strong enouph but if you think you can brok it easly then you think you can change inside that?

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.