Recovering root user password in CentOS or RHEL 7
What if you forget root user password?
RHEL/CentOS 7 has a way to recover root user password, but this will need downtime of your linux host.
To recover your root user password follow below procedure as shown in screenshots:
PRESS "e"
Step 2 : Scroll your cursor down till you see line starting from "linux16". Come to the end of line after "UTF-8" give a space and write "rd.break":
Step 3 : Once you come to shell prompt, remount "/sysroot" with "rw" permission i.e. read/write and then chroot to "/sysroot" directory:
# mount -o remount,rw /sysroot/
# chroot /sysroot/
Step 4 : Now we can go ahead and reset "root" user password using "passwd" command:
Step 5 : Once new root password is set and SELinux is ENABLED then create "/.autorelabel" file using touch command, so that it will relabel shadow file:
# touch /.autorelabel
Press "Exit"
Press "Exit"
This will reboot system and once it comes up, you would be able to login as root user with new password.
Step 2 : Scroll your cursor down till you see line starting from "linux16". Come to the end of line after "UTF-8" give a space and write "rd.break":
PRESS "CTRL + x", this will interrupt the boot process and leave you to the shell prompt :
Step 3 : Once you come to shell prompt, remount "/sysroot" with "rw" permission i.e. read/write and then chroot to "/sysroot" directory:
# mount -o remount,rw /sysroot/
# chroot /sysroot/
Step 4 : Now we can go ahead and reset "root" user password using "passwd" command:
Step 5 : Once new root password is set and SELinux is ENABLED then create "/.autorelabel" file using touch command, so that it will relabel shadow file:
# touch /.autorelabel
Press "Exit"
Press "Exit"
This will reboot system and once it comes up, you would be able to login as root user with new password.
Excellent article.Thanks for sharing....
ReplyDeleteDocker Training in Hyderabad