Forgot your password on your rhel7 server? Well there are some differences to process from rhel6. Here is how you do it.
With SELinux and systemd in the mix we have to deal with that. Here is the procedure of what needs to be done in order to recover a forgotten root password on Redhat 7 Linux:
Edit the GRUB2 boot menu and enter user single mode
Remount / partition to allow read and write
Reset the actual root password
Set entire system for SElinux relabeling after first reboot
Reboot the system from single mode
Now that we understand the procedure we can proceed with Redhat 7 password recovery.
1. Edit GRUB2 boot menu
Start your system and once you see your GRUB2 boot menu use ‘e’ key to edit your default boot item. Usually it is the first line. Once you hit the ‘e’ key, scroll down and locate a line with ‘rhgb quiet’ keywords:
Once you edit the boot line as show above press “
CTRL + x" to start booting your RHEL 7 system into a single mode. At the end of the system boot you will enter a single mode.
2. Read&Write root partition remount
Once you enter a single your root partition is mounted as Read Only
ro. You ca confirm it with the following command:
# mount | grep root
In order to mount our partition with Read/Write flag we use
mount with a
remount option as follows:
# mount -o remount,rw /
Next, confirm that the root file system is mounted Read/Write
# mount | grep root
3. Change root’s password
Still in the single mode we can proceed with the actual root password recovery. To do this we use
You will need to enter your password twice.
4. SELinux relabeling
The additional step which needs to be taken on SELinux enables Linux system is to relabel SELinux context. If this step is ommited you will not be able to login with your new root password. The following command will ensure that the SELinux context for entire system is relabeled after reboot:
# touch /.autorelabel
5. Reboot System
The final step when resetting your lost root password on RHEL 7 linux system is to reboot. This can be done with a following command:
# exec /sbin/init
After reboot you will be able to use your new root password.