Linux Root Password Recovery
Ivan Van Laningham
(with thanks to the linux-smp mailing list members)
This page doesn’t describe how to recover the root password once you’ve
forgotten it or lost it, but rather how to recover from its loss.
First, try this:
-
Reboot;
-
At the lilo: prompt, type “linux init 1”;
-
If that works, you’ll get a bash shell prompt; go to step 4, below.
-
Otherwise, go to step 1 below.
I’m running Redhat 5.2 and 6.0, but I know that the procedure is
similar on other distributions; however, I’ll only describe the procedure
for Redhat.
You need the Redhat boot diskette and the Redhat rescue
diskette; it probably helps to have another Linux machine available.
-
Insert your boot diskette in the floppy drive;
-
When you get to the Install or Upgrade? page, type rescue
at the boot: prompt and hit enter;
-
When prompted, insert the rescue disk;
-
When it’s finished loading the rescue diskette, you’ll get a bash
shell prompt.
-
mkdir /tmp2;
-
Assuming your hard disk is on /dev/hda1, type “mount -t ext2
/dev/hda1 /tmp2”;
-
If that fails, you’ll have to improvise.
-
If successful, cd to /tmp2/etc, and type “cat passwd”;
if the root passwd entry looks like this, you’re in business: “root:Wlkjlk.jo980934:.....”
(where the stuff after the second colon is readable text, like numbers
& so on)
-
If the root passwd entry looks like this, “root:*:...” you’re also
in business;
-
...and if it looks like this, “root::.....”, you’re already OK.
Just reboot and login as root with no passwd. Exit this procedure.
-
If it looks like “root:x:....”, then you need to operate on the
shadow
file, not the passwd file; everything else from here on out applies
to whichever file you’re editing.
-
You need to edit the passwd or shadow file, but vi
lives in /tmp2/bin instead of being in your path.
-
Type “/tmp2/bin/vi passwd” (or shadow, as appropriate).
-
Remove everything between the first two colons of the root passwd
entry; it should end up looking like this “root::...”
-
Save the file (passwd or shadow)!!!!!
-
Type “sync” (very important).
-
Hit “^D” to end the bash shell session.
-
The machine should reboot, and you can login as root with no password.
Main web site: http://www.pauahtun.org