How to Recover/Reset Root User Password in Linux (RedHat || CentOS || Fedora)
How come? Isn’t Linux secure enough to prevent such manipulation? So anyone can change your password?
💁♀️I mean physical access to the server should be controlled. 🙅♀️ If such a thing happened. It means that the security measures you took in place should be reevaluated and possibly strengthened to prevent unauthorized access.
✅Let’s get it going:
1️⃣The first step is to boot your system and stop right on this bootloader menu. choose the boot entry you want to utilize then press “e”. EDIT
2️⃣ Use the arrow keys to navigate to the line that starts with “linux” or “linux16”. and then Press the “Ctrl + e” key to move to the end of that line.
3️⃣Add these two words “rd.break” (without quotes).
Then Press the “Ctrl + x” key to boot into rescue mode.
you should see such a screen when it is booted. means you are in rescue mode.
4️⃣ Now let’s check where the route file system does exist and what mode is applied on.
5️⃣ We will make sysroot FS accessible in a read-write mode so we can edit. That is why we use this command “mount -o remount,rw /sysroot/”.
6️⃣ The “chroot” command allows you to change the root directory of a process and its children.
now enter your new password and confirm it.
📢Because the system was not fully booted the password file “/passwd” was not manipulated and the SELinux File is slightly wrong.
As a note: Anything you do in this recovery mode does not update the SELinux File context. so we will be touching the autorelabel so that it instructs SELinux to perform a full file system relabel on the next boot.
7️⃣Press the “Ctrl + d” twice. It will take some time to boot. Once booted enter your login and your new password.
Easy right? 😁That was all, don’t hesitate to contact me if you need any extra help.