Recover Root Password
Recover a forgotten root password on Redhat 7 Linux Selinux system
Contents[Hide]
The way on how you can reset a forgotten root password on a Linux system have not changed for many years. Resetting a root password on RHEL7 Linux system have not change much except that now we deal with - Edit GRUB2 boot menu
- Read&Write root partition remount
- Change root's password
- SELinux relabeling
- Reboot System
SElinux
and the system is now using systemd
instead of init
. Nevertheless, those who have already did reset root password on the Linux system will be with the following steps familiar. Here is the procedure of what needs to be done in order to recover a forgotten root password on Redhat 7 Linux:- We need to edit GRUB2 boot menu and enter user single mode
- Next, we need to 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 a single mode
1. Edit GRUB2 boot menu
Start your system and once you see your GRUB2 boot menu usee
key to edit your default boot item. Usually it is the first line:e
key you will see a screen similar to the one below:rhgb quiet
keywords:rhgb quiet
keywords and replace them with init=/bin/bash
as show below: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 Onlyro
. You ca confirm it with the following command:# mount | grep rootIn 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
rw
:# mount | grep rootAll the above steps are show below:
3. Change root's password
Still in the single mode we can proceed with the actual root password recovery. To do this we usepasswd
command:# passwdYou will need to enter your password twice as shown below:
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/initAfter reboot you will be able to use your new root password.
Comments
Post a Comment