What to do if you forget root password?

Although this may seem like a small catastrophe to you, it's actually very easy to recover from that situation. What you need to do is to reboot (power on) your system, but on the LILO prompt you should type something like:

LILO: Linux init=/bin/sh rw

Where Linux is the example image name, you should supply the actual data, of course. And same parameters should be provided to GRUB or any other boot loader you might use.

Now, init=/bin/sh part tells kernel to exec shell instead of init. That means that you'll end up with a very limited system, but which is fortunately capable enough for you to bravely type your new root password:

sh# passwd

And don't forget to type rw, too. Otherwise you'll end up with root partition mounted read-only. But, if you do, you can remount it read-write like this:

sh# mount -o remount,rw /

OK, after you have changed your password successfully, it's probably best to remount root partition as read-only and just press reset or power button of your computer:

sh# mount -o remount,ro /

The reason for such "drastic" action is that otherwise, e.g. if you typed reboot at the prompt, your system would try to stop myriad of services that are not actually running when you have booted with the above parameters to the kernel. So the reboot would take longer (it could even get stuck at some point) and the output of all those failed init.d scripts is definitely not for everybody's eyes. :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

And with usb keyboard

I read you information about changing password on a linux machine with init=/bin/sh, but now if I only have a usb keyboard, If I do init=/bin/sh I don't key usb support.
Did you have a solution ?

Hm, don't know much about

Hm, don't know much about USB keyboards, but if it works when you boot in regular single mode (init 1), I suppose it should work even with init=/bin/sh.

What do you normally do to make it working? Does it work on LILO prompt? Do you have USB support and HID devices support in your kernel? Maybe it's modular, so modules don't have a chance to load until some other stage in boot sequence, but in that case even standard single mode wouldn't work, right?

Do you have any option in BIOS that would help you with that problem? Something like emulate PS/2 (legacy) for USB keyboard/mouse... I think I saw something like that in some BIOS.