System Rescue Without a Password

So you lost your Linux root password.

No panic. There is a way to reset it:

  1. Turn the computer on and pay attention.
  2. When the bootloader (GRUB or LiLo) screen appears, select the partition you want to fix the password.
  3. Do not boot it yet. Go into edit mode for this partition.
  4. In the end of the kernel boot parameters line, include this init=/bin/bash.
  5. Then boot the partition.
  6. You will see a very fast boot. And right after the pure kernel initialization you’ll receive a root command line. If you try to change a password at this time (with the passwd command), you’ll get a message that means you don’t have write permissions on the filesystem.
  7. So you’ll have to put your system in a read-write state whit this commands:
    bash# mount /proc
    bash# mount -o remount,rw /
  8. All set. Now use the passwd command to change the root password.
  9. Now type the following: sync; sync; exit. Then reset the system.

Note: If the computer has a BIOS or Bootloader password that you don’t know, you won’t be able to use this technique.

The idea here is to change the default program that is executed to setup all the OS environment, right after the kernel initialization. By default it is /sbin/init, and what we did above is to change it to /bin/bash — a regular shell prompt, a command line.

2 thoughts on “System Rescue Without a Password”

  1. Another method to do so is to boot thru a LiveCD or a diskette, mount the root partition in, for instance, /old_root and then type “chroot /old_root”. After that, all you gotta type is “passwd” and change the root password.

Leave a Reply to Alexandre Coster Cancel reply

Your email address will not be published. Required fields are marked *