Let us discuss about a small topic. On RHEL 6.0 and earlier, an administrator could boot the system into runlevel 1, and be presented with a root prompt. The closest analog to runlevel 1 on RHEL 7.0 machine are the rescue.target and emergency.target both of which require a root password to log in.
On RHEL 7.0, it is possible to have the scripts that run from the initramfs pause at certain points, provide root shell,and then continue to when the shell exits. this is mostly meant for debugging however it can also be used to recover the root password.
Here is the steps to recover the password :
1. Reboot the server.
2. Interrupt the boot loader countdown by pressing any key.
3. Press "e" to edit the selected entry.
4. move the cursor to the kernel command line (the line starts with linux16.)
5. Append rd.break (this will break just before control is handed from initramfs to the actual system)
If you are recovering the root password of Virtual machine ( KVM) then you need to add serial console "console=ttyS0" along with "rd.break" otherwise we will not get the # prompt to change the password.
6. Press CNTL+x to boot with changes.
At this point, a root shell will be presented, with the root filesystem for the actual system will be mounted read-only on "/sysroot" .
From this shell we need to recover the password.
7. Remount the /sysroot as read-write mode.
# mount -o remount,rw /sysroot
8. Switch to chroot, where /sysroot is treated as the root of the filesystem tree.
# chroot /sysroot
9. Set a new password . Here i resetted my server password as redhat.
# echo "redhat" | passwd --stdin root
10. Make sure that all the unlabeled files ( including /etc/shadow at this point) get labeled during boot.
#touch /.autorelabel
11. exit twice. First will exit from chroot and second will from the initramfs .
12. At this point, Server will reboot and now you could login with the new password set to root.
Hope you find this post useful ! if you have any feedback/queries post in the below comment box.!
On RHEL 7.0, it is possible to have the scripts that run from the initramfs pause at certain points, provide root shell,and then continue to when the shell exits. this is mostly meant for debugging however it can also be used to recover the root password.
Here is the steps to recover the password :
1. Reboot the server.
2. Interrupt the boot loader countdown by pressing any key.
3. Press "e" to edit the selected entry.
4. move the cursor to the kernel command line (the line starts with linux16.)
5. Append rd.break (this will break just before control is handed from initramfs to the actual system)
If you are recovering the root password of Virtual machine ( KVM) then you need to add serial console "console=ttyS0" along with "rd.break" otherwise we will not get the # prompt to change the password.
6. Press CNTL+x to boot with changes.
At this point, a root shell will be presented, with the root filesystem for the actual system will be mounted read-only on "/sysroot" .
From this shell we need to recover the password.
7. Remount the /sysroot as read-write mode.
# mount -o remount,rw /sysroot
8. Switch to chroot, where /sysroot is treated as the root of the filesystem tree.
# chroot /sysroot
9. Set a new password . Here i resetted my server password as redhat.
# echo "redhat" | passwd --stdin root
10. Make sure that all the unlabeled files ( including /etc/shadow at this point) get labeled during boot.
#touch /.autorelabel
11. exit twice. First will exit from chroot and second will from the initramfs .
12. At this point, Server will reboot and now you could login with the new password set to root.
Hope you find this post useful ! if you have any feedback/queries post in the below comment box.!
the best linux blog..appreciate your hard work!!
ReplyDelete