Click to See Complete Forum and Search --> : Forgot your root password?


Lansing_Banda
October 5th, 2004, 06:18 AM
Say you set up a box and installed your favorite linux distro on it. Say that you wanted to try a spiffy new password that you think you will remember forever. Say you don't see the box for a month and that password has slowly seeped out of your brain. What do you do?

Step 1:
Find you a bootable linux OS (knoppix comes to mind), burn it, and boot it.

Step2:
When you have finished booting, mount your local drive:


mount /dev/hda1 /mnt/test/


Step 3:
Change the root filesystem to the local hard drive


chroot /mnt/test /bin/bash


Step 4:
Change yourself a password


passwd


Step 5:
Shutdown the OS, remove the disk, and reboot.

Welcome back to your system!

the_JinX
October 5th, 2004, 07:57 AM
If you use lilo there's another way..
This is a repost, the origional can be found here: http://jinx.etv.cx/tut/index.php?url=liloroot.bbc

You have found your old linux box..
ah.. nostalgia
you just can't remember that ****ing root password..

you could boot from a bootdisk and eddit the /etc/shadow but that's not the nicest way..

on most computers you can give the kernel added options in the lilo bootscreen..

you can use the init= option to set an aplication to be started after boot :D

adding the line init=/bin/bash rw should boot the puter and drop you into a root console on the read-write (rw) mounted root filesystem..


so remember, if your normal kernel boot image's name is linux and the passwd executable is located in /usr/bin then:

linux init=/usr/bin/passwd rw

allows you to reset your root password in the neatest way !!

playing around with init might result in a Kernel Panic !
but after a reboot the password should be changed..



Now, what do we do about that..
We don't want anyone that read this doing it on my box..

You could swich to an alternative boot loader, but let's not do that just yet..

open /etc/lilo.conf in your favorite editor.

add these lines somewhere at the top (right after prompt would be appropriate),
and ehm.. insert your own password there ;)

restricted
password=1ns3rtp4ssw0rdh3r3

save and execute lilo
lilo might warn you and well it's advice is quite clear.. Warning: /etc/lilo.conf should be readable only for root if using PASSWORD
chmod 600 /etc/lilo.conf

be sure to man lilo.conf and find out more about lilo