Sometimes a user may forget the password for the root account in Linux, and this could lead to a big problem sometimes, how to overcome from this scenario. So here is what you can do in order to reset the root account.
The first thing which you can try is, if sudo user is added to your server, you should be able to reset the password for the root account using sudo user. Just login with sudo user and execute the following command.
# sudo passwd root
Second, If sudo user is not added to the server then you need to follow the following steps.
1) reboot the server, Interrupt booting the server by pressing any key, you will see the grub screen.
2) Choose the kernel and edit it by pressing 'e'
3) Find the line which is being started with linux16 and append 'rd.break' at the end
4) After that press CTLR+x to boot the server into emergency mode
5) Now remount sysroot by using the following commands
# mount -o remount,rw /sysroot
# chroot /sysroot
6) Now, set the new password for the root account
# passwd
7) Make sure to relabel all the unlabeled files of the SElinux by touching the hidden file autorelabel
# touch /.autorelabel
8) then type 'exit' twice to reboot the server this might take some time to boot the server as it relabels the SElinux
And that's it, You should now have the root password access to this server
Please do let us know if you have any questions on this in the comment box and follow me for the series of Linux blogs
If you enjoyed this post, I'd be very grateful if you'd help it spread by emailing it to a friend or sharing it on Twitter or Facebook. Thank you!
really well expliained and looking forward for more from you
ReplyDelete