Root Password Recovery



If you've forgotten your root password, unfortunately it is shockingly easy to change the password. The trick is to boot directly into single user mode.

Boot your machine, then at the LILO prompt enter:

linux single

Then you should get a prompt that looks like sh-2.05#, from there type:

passwd root

Then follow the prompts to change the password.

Next, type

sync; reboot

That's it! Single user mode is also helpful if you want to do maintenance without all the services running, it's something like "safe mode" in Windows.


Securing Your System:

The above demonstrates why securing your server's console is important! In about 5 minutes, anyone with physical access to the computer can change the root password and get root access by passing the linux single option at the lilo boot prompt. LILO can be protected against this by putting a password on options passed to the kernel.

In /etc/lilo.conf, you'll see your definition for the boot image, for example:

image=/vmlinuz
label=linux
initrd=/boot/initrd-2.4.x.img
read-only
root=/dev/hda6

After this add:

password=yourpassword

restricted

Exit, and run "/sbin/lilo". If someone tries to pass an option like "single" they'll need the password. Next, make the lilo.conf file read-writeable by root only:

chmod 600 /etc/lilo.conf

Be aware that these passwords will merely slow down the determined attacker. They won't prevent someone from booting from a linux boot floppy, and mounting your root partition. The only way to get around this would be to disable booting from a floppy in your computer's BIOS, then password protect the BIOS.