How to Recover/Reset Root User Password in Linux (RedHat || CentOS || Fedora)

Ahed Bahri
3 min readJan 13, 2023

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

Bootloader menu

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.

Rescue mode

3️⃣Add these two words “rd.break” (without quotes).

rd.break

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.

rescue mode

4️⃣ Now let’s check where the route file system does exist and what mode is applied on.

route fs

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/”.

remount Fs /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.

Change root directory

📢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.

relabel on the next Linux boot

7️⃣Press the “Ctrl + d” twice. It will take some time to boot. Once booted enter your login and your new password.

Authenticating

Easy right? 😁That was all, don’t hesitate to contact me if you need any extra help.

--

--

Ahed Bahri

Computer Engineering Student, i’ve got a big passion in Computer Technology, programming and in solving problems. Https://www.behance.net/BahriAhed 💖