Lost Root Password

Here is another one of those tips that was inspired by co-worker.   I walked into work to start my shift when I was abruptly interrupted by, let’s call him, "Bob".  Bob was like, "Darn it!!!  I can’t believe I forgot my root password for my box AND my regular users’ password expired over the weekend!!!" 

Stopping short of calling him a moron, in my "Compton gangsta voice" I was like, "Yo, Bob, calm the F*** down before I b**ch slap you!"  (Yeah, I’m a tough guy, what can I say.)   I then proceeded to calm Bob down.  He was ranting and raving about his how he needed to get his "Grandma’s favorite cookie recipe" that was stored on that box.  (NOTE: Substitute "Grandma’s favorite cookie recipe" for “mp3’z, moviez, and warez”)

Anyway, once I was able to calm him down I re-assured him that not all was lost. 


Thankfully, there are several ways that you can retrieve your forgotten password from Linux.  Many people use a LiveCD, usually one from Knoppix (http://www.knoppix.net/) or from a floppy boot disk.  However, his box didn’t have a floppy drive OR a CD-ROM drive since they aren’t needed for the job that we do at work.  The next thing you would probably try would be booting into "linux single" mode.  Depending on what system and bootloader you have, that will happily drop you to a linux root shell.  But on some systems (the RH flavor), it will drop you into the dreaded emergency prompt:

Give root password for maintenance
(or type Control-D for normal startup)

If you are lucky, you can just enter CTRL-C and init will let you log in.  But modern versions of LILO are “smarter” than that and trap CTRL-C so you might be SOL.
All is not lost however. 

His particular setup looked like this:

  • OS: Fedora Core3
  • Boot Loader: LILO 

Here is what I told him to do since we have physical access to his machine.  The instructions may vary for your setup:

  1. After POST and from the “LILO:” prompt I told him to type this:

      LILO: linux init=/bin/bash rw

Here we are passing read/write booting options to LILO which will mount “/” in read/write mode.  The kernel will then simply load a bash shell with rootly powers.  It will not do any file system checking or load any of the init scripts. 

  1. Once the bash shell has been loaded, you can type “passwd” to change the root password.  Once the password has been reset, DO NOT, I mean, DO NOT reboot, log out, or do anything that will kill that current shell. 
  2. There isn’t a safe way or shutting down the system at this point and you will be risking file system corruption if you do any of the above.  Instead do this:

     # mount –o remount,ro /

That will remount the root partition in “read-only”mode which will enable you to safely hit the reset button, reboot, and log in as you normally would.

Once “Bob” was able to finally log into his box he was happily enjoying his “Grandma’s favorite cookie recipe’s”.  You should have seen the expression on his face.  If you could imagine what a fat kid would look like while eating cake, then that’s how giddy he was (minus the caked, plus the fat).  I suggested that he go home and tell his mommy to sew his password to his underwear right next to his initials.  He wanted to act tough but he knew his fighting skills were those similar to a 10 year old girl so he just took it, like a 10 year old girl.

Hope this saves you from acting like "Bob".  Hi "Bob", I know you are reading this! 


About this entry