Resetting the forgotten root password in RHEL 4.0
There are many ways to reset your forgotten root password. Following are some that I have tried.
Using RHEL Boot CD
The one that I normally go for is by using an alternate boot medium. It may be usb or a cdrom that can be helpful. Many systems these days provide usb booting option. Well we will go for the other one that is cdrom. We just have to make our system ready to boot from the cdrom and this can be done in the BIOS settings. I wont go much into details of BIOS, you will find plenty of material available on the net to do so.
Boot by cd1
Press F5 for rescue mode
Type linux recue at boot:
Choose continue to mount the linux partition on /mnt/sysimage
Finally it gives you a shell prompt
type # chroot /mnt/sysimage
Now you can edit the /mnt/sysimage/etc/shadow file through vi editor
# vi /mnt/sysimage/etc/shadow
Cut out the password from the password field from root in shadow file, save the file and reboot the system.
This will give a passwordless root account.
Using GRUB Menu
At GRUB Boot screen, hightlight the kernel image and press 'e'.
Then press 'e' at line starting with “kernel”.
Give space and type single or rw single init=/bin/bash
Hit enter & then press 'b' to boot the system.
The system will boot to passwordless root shell.
Type
# passwd
And we are done
Using Ubuntu 10.10 Live CD
Boot the system using Ubuntu 10.10 Live CD.
Open a terminal.
Type # sudo fdisk -l to know your root partition.
In my case it was /dev/sda2. After you get to know your partition, type
# sudo mount /dev/sda2 /mnt
Then we have to make /mnt as our /.
# sudo chroot /mnt
Finally change your password
# passwd root
Or we can also go for editing /etc/shadow instead of passwd command
# vi /mnt/etc/shadow
Using Ubuntu Live CD
boot the system with ubuntu live cd.
open a terminal
# sudo fdisk -l
# sudo mount /dev/sda1 /mnt
# sudo chroot /mnt
# passwdOr, we can edit the /etc/shadow file using any editor that you are comfortable with. I had used nano editor.
# nano /etc/shadow
Cut out the password from the password field from root in shadow file and save the file. It should look somewhat like the below pic.
Using GRUB Menu
Well in this method you need to do a “little hack” to the grub loader. Sounds cool? Infact its lot more easier.
Boot the system.
Hold down the shift key while booting.
GRUB Menu appears.
Highlight your os image & press 'e'.Find the line starting with 'linux' and replace 'ro' with 'rw' and append init=/bin/bash at the end of the line.
Press ctrl+x
System will boot to passwordless root shell.
# passwdHere too we can go for editing the /etc/shadow file through any editor you like in case the passwd doesnt work.
Cut out the password from the password field from root in shadow file and save the file
Finally,
# reboot -f
And we are done.
made my morning much easier, nice one!
ReplyDeleteNice this is definitely what I needed as I didnt want to use a LiveCD for this. All the other links were just pure copy-pasta. However this one was comprehensive and included screenshots. However I didnt need the screenshot just a better explanation which this one also implied as I kept appending on the wrong line. As well saving myself a double mount. Thanks
ReplyDeletePassword reset quick review.
ReplyDeleteNice post.
Keep it up
http://sankar-information-security.blogspot.com/