Purpose: If you have been using Linux for a while you will most certainly find a situation where you have forgotten or lost your “root” users’ password (Admin password) and you have no clue how to regain your root login prompt. As long as you have physical access to your machine (and may be your hard drive) you can do it in less than three minutes.
Step 1: Obtain a LiveCD
Your fist task is download a standard LiveCD like KNOPPIX, Ubuntu LiveCD or even a Debian LiveCD. Once you download the ISO image, burn it on to a CD or a DVD. See here if you want to create Debian LiveCD in minutes.
Step 2: Boot from LiveCD
Next insert this LiveCD in the CD-ROM of your system and boot from the LiveCD.
Note: You might have to go to the BIOS and change the Boot order option to boot from CD-ROM instead of Hard Drive. If you don’t have a regular IDE CD-ROM, then get a USB CD-ROM. If you are using a relatively modern computer, you should have the ability to either boot from a “traditional” IDE CD-ROM or a USB CD-ROM.
Step 3: Mount your hard drive
Now once the LiveCD finishes booting, go to the shell prompt and mount your hard drive which has the Debian installation whose root password you would like to reset.
#mount /dev/<device-name-and-partition> /mnt/
# mount /dev/hda1 /mnt
# mount /dev/sda1 /mnt
Step 4: chroot into your partition
The next step is to “chroot” into your partition that you must mounted:
# chroot /mnt/
Now you will be in the shell prompt environment of your Debian installation on that disk
Step 5: Reset the root password
Now give the following command and give the new desired root password:
# Enter your new UNIX password:
# Retype new UNIX password:
Also you can reset a password for another user (not root) once you gain access to root user account.
Step 6: Un-mount and reboot
Finally un-mount your hard drive:
# umount /mnt
and reboot/restart your computer and boot from hard drive and you should be able to use the password that you choose above (Step 5) to regain the root prompt.
Q: Are there any other methods to recover password instead of resetting?
A: Please note that there are other methods too that you can use to reset the root password and in some cases even recover the root password. I have discussed here the most simplest method to do so. If all you care is to gain the root prompt without the need to retain the old password, then the LiveCD method is the best.
Q: What else can you use other than Live CD?
A: If you do not have a LiveCD, then the other method is to attach your hard drive that you want to fix to an existing system that already has a hard drive that boots some kind of Linux. For example, take your hard drive to your friend’s computer that boots Linux and attach it to it. After that you can follow from Step 3 onwards. Just make sure you substitute the correct disk in the “mount” command.
That’s it. You are all set.