Recover root password and set a new password for root (RHEL7)
Setting a root password is not a very big deal, you know how to do it, but suppose if you have forgotten what your CentOS/RHEL system’s root password is, then it could be a huge headache to recover and reset the root password.
As a System Administrator, you do it almost regularly. But the trick is when you forget the root password then how will you fix it?
So, to reset root password it requires rebooting your CentOS 7 or RHEL machine, and then edit the GRUB parameters during boot time. For this, you need to interrupt the boot process. It is a bit tricky as the grub menu do not want a very long, so you need to be alert while entering the grub menu.
So follow the process below, and I hope this will help you to reset root password very easily.
The procedure that you need to follow in order to recover a forgotten root password on Redhat 7 Linux or Centos 7
There are some steps we need to follow to reset the root password.
- We need to edit GRUB2 boot menu and enter user single mode
- Next, we need to remount the ” / ” partition to allow read and write
- Reset the actual root password
- Then on the next step, need to set the entire system for SELinux relabeling after the first reboot
- Reboot the system from a single mode
So let’s start the process…
At first, reboot your system ==>
Then press the “space bar” when the system boots up, to prevent automatic OS selection.
Highlight your Operating System and then press “e” to edit.
go to “Linux 16” number line
Press the “end” button and press the spacebar again.
Type “rd.break” and press ” ctrl+x “
wait for a while… a command line will come up.
type the following commands below…
# mount -o remount,rw /sysroot/
# chroot /sysroot
# passwd root
— type a new root password
— reenter password
# touch /.autorelabel
This will end up rebooting the system. The time for reboot may take up to 2-3 minutes, which is very normal. Wait for the system to boot properly.
Now after the system reboots, you should then be able to log in using your root user’s new password that you have changed already.
You should now have arrived at the login screen. Here you will be able to login to your root account using your new password. (You may need to log in as a normal user then “su” to root depending on your system set-up).
So, guys, I have tried my best to simplify things so that you can have a better understanding and user experience. Now it’s your turn to pay me back.
I am expecting your responses. If you like this content inspire me by just commenting or liking this article. Your responses will motivate me to do better and deliver better. Even if you do not like this article then also tell me by commenting below. I will try my best to improve my skill.
So thank you guys, Have a good day.