"Journey towards new learning"

Resetting ROOT Password in RHEL7





Changing the root password in RHEL7 is different than RHEL6. There are a lot of changes in RHEL7. Changing root password is easy in RHEL 7. We had to deal with init in RHEL6 but now we need to deal with SELinux and systemd. The procedure is similar and easy to understand. Below procedure will make you understand what needs to be done in order to reset/recover root user password on RHEL7.
1    1. GRUB Editing
      2. Entering in Single mode
      3. Mounting / (Root) partition with read write permission
      4. Root user Password change
      5. SELinux relabeling
      6. Rebooting the system
   
      1. GRUB Editing
      Power on the machine and wait till below screen appears. Now select the GRUB boot menu and press “e” to edit default boot 

       Once you press the “e” then below screen would appear with some information

      
     Press up and down arrow key to find the line starting with “linux16”, Once you get the line then move the cursor on “rhgb quiet” keywords,Remove the“rhgb quiet”keywords and replace with “init=/bin/bash
    

      2. Entering in Single mode
Once the GRUB menu is edited then now it’s turn to start system into single mode. Press         “CTRL+x” This will take user to bash shell prompt


      3. Mounting / (Root) partition with read write permission
He is where game starts. User doesn’t get RW access to root partition because user is in single mode. / (root) is mounted as read only in single mode. To confirm user can give below command to check   
# mount | grep root


Now user has to remount the partition with “rw” permission
# mount –o remount,rw /
Once the user makes partition rw then now it’s turn to verify again


4. Root user Password change
Single user mode allows user to change root password, To change he password type below command
# passwd


5. SELinux relabeling
If you are not using SELinux you could reboot at this point and everything would work. Bydefault RHEL7 uses SELinux in enforcing mode.  When you run passwd command system creates new /etc/shadow file but we are in single mode so SELinux is not running in this mode and file would be created with no SELinux context. This is dangerous and can cause problem at boot time.  To fix this type below command
# touch /.autorelabel


This command will perform relabeling on the amount of file we have on the file system.

6. Rebooting the system
Here we are ready to reboot the machine. This is the final step where we dealt with resetting RHEL7 root password.
# exec /sbin/init



Summary
As shown above we can reset the RHEL7 root password if we forget or want to recover. This can be done editing GRUB boot menu, changing the file system with read/write privileges, creating new password and changing the SELinux context.
Rebooting machine can take few minutes or more depending on how many files are stored in file system. Once system is rebooted then user is ready to login with new password.

I hope this has been informative for you. If it seems helpful then Like, Share and Don’t forget to subscribe and follow me for the upcoming posts
https://www.youtube.com/channel/UC0-p23p1xWsZsTXHUQ7CiJg
https://www.facebook.com/networkinginfo/
https://twitter.com/Dj1Pali
https://www.instagram.com/a_bhartiya_rider/
https://www.linkedin.com/in/dinesh-jangid-515b6a23/

  

No comments

Powered by Blogger.