Saturday, 7 May 2016

reset rhel7 root password

In the RHCSA examination they ask to reset the root password, In this article we are going to learn how to reset rhel7 root user password.

Whenever you type user password incorrectly it will shown an above error. 

 Immediate After Right side of the corner there is a power button Click on that power button and Click on Restart Server. Server will restart.

 While restarting of server you have to press any key to stop the OS booting process yet the stage of Kernel. As shown in above screen shot kernel line will stop. Then Press 'e'

After pressing key 'e' then kernel lines will be edited. As shown in below screenshot
if you see there is a line start with "linux16" go to that line press 'END' key to go last of the line. In END of the line write "rd.break console=tty1" (without quotations). Then Press CTRL+x

Server will go to Single user mode. As shown in above screen shot.
In this mode /sysroot file system bill be mounted as ReadOnly. We have to make /sysroot as ReadWrite then only we can able to change the password.

Changing password means we are indirectly writing the encrypted password in /etc/shadow file.
To mount /sysroot file system in ReadWrite run below command
# mount -o remount,rw /sysroot

Now change to root using below command
#chroot /sysroot

Now prompt will be changed to Shell.
# passwd 
New Password: redhat
Retype Password: redhat

Now root password has been changed to 'redhat'. If you reboot the server will not come back. in RHEL7 by default SELinux is in enforced mode we have to relabel the SELinux inorder to bring back the server in Normal Stage.

To Relabel the SELinux run below command
# touch /.autorelabel

Now type exit exit two times System will be restart
 sh-4.2# exit
switch_root:/# exit

That's it now RHEL7 server will be back after that type username: root and Password: redhat.

Successfully rested RHEL7 root user password.

No comments:

Post a Comment