Link to home
Start Free TrialLog in
Avatar of j_k
j_k

asked on

forgot root password on RH Linux 6.1

I built a new rh linux 6.1 server about 2 months ago and just now starting to use it.  I hadn't yet made any user accounts and I forgot what root's password is.  Is there any way to wipe out what password is there, maybe booting from cdrom?  How would I access the passwd file? Any ideas?
Thanks
Jak
Avatar of fbjean
fbjean

It is write in the book.
There is no way to recover a forgot root passwd .
You just have to reinstall.
No other way.
Sorry.

Good luck
I disagree totally with fbjean.

Never say never man! nothing is impossible or out of the question.

You can recover.

Basically you boot to single user mode!

at the lilo prompt type "linux single <return>".
you will come to the prompt right away
no login or anything (which is really a bit of a security hole but if phsical access to the computer is protected then it's not).
If lilo does not allow you to type into the prompt then you may need to hold down the shift key to get access to it.
if it prompts you for a password I hope you know it... if not there are other ways.

Since you are root, type chpasswd
type in a new one.. reboot.

If you cannot get into single user mode because it has been secured (sometimes this is done)

If the above didn't work then see if you can create yourself a linux boot disk.

When you've done that boot up the disk.
If necessary login.
Then at the command prompt type:
mount /dev/hda1 /mnt/<something> or mount /dev/sda1 /mnt/<something>
or whatever partition and drive contains
the /etc directory tree.

This is where it gets interesting.

If you're running a ramdisk type of boot repair disk copy the file from /etc/passwd on the disk you just mounted to the /etc/passwd on your repair disk.

Next type passwd root
enter in a new one.

copy the passwd file back to the real /etc/passwd on your mounted disk which might be /mnt/<something>/etc

reboot and viola! you can login using the password from before.

by the way,  backup your passwd file before you make changes.

If you're using shadow passwords.. umm, not sure but the procedure might be more tricky..

another thought is, modify your system to allow you to login in single user mode... then follow the original procedure which was easier..
As for enabling you go single user I'm not sure how to fix it if it is passworded single user.. it seems to me that you can make the single user logon screens appear by modifying the boot scripts. so there are lots of ways it can be done.

I hope you find this a satisfying answer.
Avatar of j_k

ASKER

Thanks Matt,
This is the kind of info I was looking for.  I'll try somethings today like that.
Jak
This is a cut and paste from Linux Gazette from the answer guy... on how to recover froim a lost password,it's a good source for alot of info.

1. Reboot
(try [Ctrl]+[Alt]+[Delete])
2. During the LILO prompt type:
(kernel/image name) init=/bin/sh rw
.... note that's usually going to be just:
linux init=/bin/sh rw
3. This should start the Linux kernel,
with the root filesystem mounted in read/write mode. The cool thing is that none of your normal init processes (like the gettys that ask for your name and call the login program) will be started.
4. (Maybe) mount your /usr filesystem with a command like:
mount /usr
5. Change your root password with a command like:
passwd
6. Flush the cache buffers:
sync; sync; sync
7. (Maybe) unmount /usr:
umount /usr
8. Remount the root fs in readonly mode:
mount -o remount,ro /
9. Let init clean up and reboot the system:
exec /sbin/init 6
.... there is a "6" (six) at the end of that command.
That's it. Don't worry about the couple of lines where I said '(Maybe)' --- you can follow those steps too, if you don't understand. The errors from unnecessarily executing those steps are harmless.
Avatar of j_k

ASKER

Thanks,
Lilo: linux single was all it took to get to the # prompt.  passwd command worked from there. Then booted normally and sucessfully logged in.  All Done.  I believe Matt_hooked should propose his as an answer since that was were I got the info first.
Jak
ASKER CERTIFIED SOLUTION
Avatar of matt_hook
matt_hook

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of j_k

ASKER

thank you