Search:  
Gentoo Wiki

HOWTO_Reset_a_Lost_Root_Password


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

Overview

The basic idea behind this is to boot from the LiveCD, chroot into your system, and run the passwd program to change the root password. Because you are 'inside' the Gentoo environment on your hard drive, your password on your hard drive will be the one that is updated.

Note: If possible, it is much simpler to append "single" to the kernel options in your bootloader. The system will start up in a minimal runlevel, dropping you off at a shell as root without prompting for a password. The passwd command can then be used to change the forgotten password as below.

Procedure

Boot from the LiveCD. Any of them will do, as long as it matches your architecture. From the LiveCD prompt, you want to mount your Linux partitions. You will probably want to mount every partition that would otherwise be mounted if you booted normally. Consider the following partition table (this is the default partition table in the gentoo 2005.1 handbook):

Partition Mount Point
/dev/hda1 /boot
/dev/hda2 swap
/dev/hda3 /

In this case, nothing more than hda3 is necessary. However, when in doubt, mount it. Here is how you would go about that:

mount /dev/hda3 /mnt/gentoo
mount /dev/hda1 /mnt/gentoo/boot
mount -t proc none /mnt/gentoo/proc

The last mount command mounts the special /proc directory, because certain programs will request access to it. Remember: order matters! /boot and /proc are all inside /, which is why they are mounted AFTER / itself! Also, for such a small excursion into your system, you probably will not need to activate your swap.

Now that your system is mounted, the next step is to chroot into it. This step is easy enough; simply run the following command:

chroot /mnt/gentoo /bin/bash

Your prompt will change slightly to reflect the transition from the LiveCD environment to your computer. As far as the programs know, you have just logged into the root account on your hard drive. So change your password:

passwd

Type exit to exit the chroot, and reboot to reboot the machine. Take out the LiveCD before the boot process starts, and you should now be able to log into your machine as root with the password you just set.

Notes

Not all programs are fit to be run in this type of environment. However, the passwd, and other basic applications like useradd are generally fine. In fact, you can use this to your advantage. While you are in the chroot, you can do things like add users or change the passwords of users other than root. Refer to the documentation on these commands to find what all you can do.

Conclusion

Congratulations, you have just learned how to use any Gentoo LiveCD to your advantage during system recovery. Enjoy!


Addition

If you're using Linux: Fedora Core, you can still reset your password without the need to go through all the above.

At the Fedora Core boot-prompt that asks which linux to boot... Hit the 'a' key on your keyboard.

You will be looking at a screen prompt similar to this:

grub append> ro root=/dev/VolGroup00/LogVol00 rhgb quiet

Now you add another keyword called "single", and it should look more or less like this:

grub append> ro root=/dev/VolGroup00/LogVol00 rhgb quiet single

Ok, now hit the [Enter] key.

Soon you will get a normal linux prompt that looks like this:

sh-3.1# _

Type in the command "passwd". This will ask you for the new root password and you'll have to confirm it a second time after the first "password and [enter]" key approach.

After that you can reboot by typing the command: reboot

Hola! its done. You can now login with your new root password.

Good luck.

Jacques F. Mostert. South Africa. greenrayder (at) gmail (dot) com.

Alternative

If your system is not damaged and your bootloader allows you to edit/add kernel-parameters

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Reset_a_Lost_Root_Password"

Last modified: Fri, 05 Sep 2008 23:24:00 +0000 Hits: 39,000