Skip to main content

How to reset/break root password in RHEL / CentOS 7 ?

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!



Comments

  1. really well expliained and looking forward for more from you

    ReplyDelete

Post a Comment

Popular posts from this blog

How Linux can help you to boost your career?

Hello there, you might have heard the term called Linux. Do you know what exactly it is? How this will help you to boost your career? And, do you want to learn it? If you are looking for the above queries then you are on the right page, don't worry just stay tuned. This article will help beginners to understand Linux and to get started with it. What is Linux? Linux is an operating system (OS) just like other OS like Windows and UNIX. In fact, it has some awesome features than other OS. That is why it is being used everywhere from IT industries to your home appliances. It was developed by  Linus Torvald  (1991). It is an Open source OS, which means it is freely available for everyone, you can install the OS without purchasing any license, and also by using its source code people can modify it and develop a new distribution (OS).  Why Linux? In today's world, Linux is everywhere. It is one of the most trustable OS. This is the reason why it is being used widely from the sup...