So you lost your Linux root password.
No panic. There is a way to reset it:
- Turn the computer on and pay attention.
- When the bootloader (GRUB or LiLo) screen appears, select the partition you want to fix the password.
- Do not boot it yet. Go into edit mode for this partition.
- In the end of the kernel boot parameters line, include this init=/bin/bash.
- Then boot the partition.
- 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.
- So you’ll have to put your system in a read-write state whit this commands:
bash# mount /proc bash# mount -o remount,rw /
- All set. Now use the passwd command to change the root password.
- 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.