HOWTO: Reset your lost/forgotten root password on Debian systems
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/
Example:
# mount /dev/hda1 /mnt
or
# 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:
# passwd
Output:
# 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.
Additional notes:
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.
Happy Rooting


Email Subscription









July 12th, 2009 at 10:58 am
[...] 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. More here [...]
July 13th, 2009 at 6:50 am
Hi, what about setting init=/bin/bash to the kernelline and using passwd;reboot ?
Reply to this comment
February 19th, 2010 at 6:28 pm
Tried the init= method, didn’t work
Reply to this comment
August 19th, 2010 at 3:26 am
Hi,
Can we just remove the encrypted password in shadow file and replace it with asterisk?
Reply to this comment
May 31st, 2011 at 3:46 am
Just give a suggestion here:
to Easily find what is the device name and partition, there is one command than can show the existing device name:
fdisk -l
Reply to this comment