Home Fedora How To Reset Root Password In Fedora Linux 39, 38, 37, 36

How To Reset Root Password In Fedora Linux 39, 38, 37, 36

A Step-by-Step Guide To Reset Forgotten Root Password In Fedora Linux.

By sk
Published: Last Updated on 36.5K views

Have you forgotten the root password in Fedora? Or do you want to change the root user password in your Fedora system? No problem! This step by step guide walks you through the steps to change or reset root password in Fedora Linux operating system.

Reset Root User Password in Fedora Step by Step

We can change the forgotten root password from Emergency mode in Fedora in two ways. The first method should work on latest Fedora 39, 38 versions and CentOS Stream 9 systems. And the second method should work on older Fedora versions.

Method 1 - Change Root Password in Fedora 39, 38

This steps provided below are officially tested on the latest Fedora 39 and 38 versions.

Step 1 - Edit Boot Entry in Grub Menu

Power on your Fedora system and press ESC key until you see the GRUB boot menu. Once the GRUB menu is appeared, use the arrow keys to select the Fedora kernel you want to boot and press 'e' to edit the boot parameters.

Grub Boot Menu in Fedora 39
Grub Boot Menu in Fedora 39

Here is the Grub menu of Fedora 38:

Grub Boot Menu in Fedora 38
Grub Boot Menu in Fedora 38

Step 2 - Boot into Emergency Mode

In the next screen, you will see all boot parameters. Find the line that starts with "linux ($root)/vmlinuz..." and press the END key or CTRL+e to go to the end of this line.

Add the following line at the end:

rw init=/bin/bash
Boot into Emergency Mode in Fedora Linux 39
Boot into Emergency Mode in Fedora Linux 39

After adding the line, press CTRL+x or F10 to boot into emergency mode.

Step 3 - Reset Forgotten Root Password in Fedora

Since you used rw init=/bin/bash, your root filesystem should already be mounted as read-write. However, if you need to remount it, you can use: mount -o remount,rw /.

Now, reset the root password by typing passwd and then entering a new password when prompted.

passwd

Or,

passwd root

Confirm the new password by retyping it.

Reset Root Password in Fedora 39
Reset Root Password in Fedora 39

Step 4 - Enable SELinux Relabeling

After resetting the root password, you should relabel the filesystem to ensure that the security contexts are correct if your system uses SELinux.

To ensure SELinux contexts are correct on your next boot, create a file that will trigger automatic relabeling:

touch /.autorelabel
Enable SELinux Relabeling on Reboot in Fedora
Enable SELinux Relabeling on Reboot in Fedora

Step 5 - Reboot Fedora

Finally, exit the single user mode and initialize the rest of the boot process by running the following command:

exec /sbin/init
Initialize Boot Process
Initialize Boot Process

Wait for SELinux relabeling process to complete. It will take a few minutes depending upon the filesystem's size and speed of your hard drive.

SELinux Relabeling Process
SELinux Relabeling Process

If you only see the Plymouth boot screen, simply press ESC key to view the SELinux progress.

Step 6 - Login to Fedora

After the filesystem relabeling is completed, you can log in to your Fedora system with new root password.

Switch to Root User in Fedora Linux 39
Switch to Root User in Fedora Linux 39

If you can able to switch to the root user with the new password, congratulations! You have successfully reset root user password in Fedora 39 or 38.

The above steps are same for Fedora 37 and older versions. I also have provided a slightly different method to change root user password in Fedora Linux in the following sections.


Alternative Method:

If you can't reset the root password from the single user mode, try to do it using a Fedora live CD or USB as described in the following link:


Method 2 - Change Root Password in Fedora 37, 36, 35

The following steps have been officially tested on Fedora 37, 36 and 35 versions. The steps provided below are also same for resetting root password in older Fedora versions and Fedora Silverblue edition.

Step 1 - Edit Boot Entry in Grub Menu

Power on your Fedora system and press ESC key until you see the GRUB boot menu. Once the GRUB menu is appeared, choose the Kernel you want to boot and hit e to edit the selected boot entry.

Grub Boot Menu in Fedora 37
Grub Boot Menu in Fedora 37

Step 2 - Find ro Kernel Parameter

In the next screen, you will see all boot parameters. Find the parameter named ro.

Find ro Kernel Parameter in Grub Boot Entry in Fedora 37
Find ro Kernel Parameter in Grub Boot Entry in Fedora 37

Step 3 - Modify ro Kernel Parameter

Replace the 'ro' parameter with 'rw init=/sysroot/bin/sh'(without quotes, of course). Please mind the space between "rw" and "init=/sysroot...". After modifying it, the kernel parameter line should look like below.

Modify Kernel Parameters in Grub Boot Entry in Fedora 37
Modify Kernel Parameters in Grub Boot Entry in Fedora 37

After changing the parameters as shown above, press Ctrl+x to enter into the emergency mode i.e. single user mode. You will be again prompted to press the ENTER key for maintenance.

Step 4 - Mount Root File System in Read/Write Mode

From the emergency mode, enter the following command to mount root (/) file system in read/write mode.

chroot /sysroot/
Mount Root Filesystem In Read, Write Mode In Fedora 37 Linux
Mount Root Filesystem In Read, Write Mode In Fedora 37 Linux

Step 5 - Reset Forgotten Root Password in Fedora

Now change the root password with passwd command:

passwd root

Enter the root password twice.

Reset Or Change Root Password In Fedora Linux
Reset Or Change Root Password In Fedora Linux

For demonstration purpose, I have used a simple password. But I highly suggest you to use a strong password.

Step 6 - Enable SELinux Relabeling

After resetting the root password, run the following command to enable SELinux relabeling on reboot:

touch /.autorelabel
Enable SELinux Relabeling on Reboot in Fedora Linux
Enable SELinux Relabeling on Reboot in Fedora Linux

Heads Up: If you do not do SELinux relabeling, the boot process may fail. You may have to do a hard-reboot and start back at step 1.

Step 7 - Reboot Fedora

Finally, exit the single user mode and reboot the Fedora system to normal mode by running the following command:

exit
reboot

Wait for SELinux relabeling process to complete. It will take a few minutes depending upon the filesystem's size and speed of your hard drive.

If you only see the Plymouth boot screen, simply press ESC key to view the SELinux progress.

SELinux Filesystem Relabeling in Progress in Fedora
SELinux Filesystem Relabeling in Progress in Fedora

Step 8 - Login to Fedora

After the filesystem relabeling is completed, you can log in to your Fedora system with new root password.

Login as Root User to Fedora
Login as Root User to Fedora

Conclusion

In conclusion, resetting the root user password in Fedora from single-user mode is a straightforward process that can be accomplished by following these simple steps:

  • Boot into single-user mode by adding the rw init=/bin/bash or rw init=/sysroot/bin/sh parameter to the kernel line in the GRUB menu.
  • Remount the root filesystem with read-write permissions using the mount -o remount,rw / command.
  • Change the root password using the passwd command.
  • Enable SELinux relabeling by executing the touch /.autorelabel command.
  • Reboot the system using the reboot command.

Once the system has rebooted, you should be able to log in using the new root password.

As you can see, the steps to reset forgotten root password in Fedora 39 and 38 and older versions are fairly easy and exactly same as resetting root password in RHEL and its clones like CentOS, AlmaLinux and Rocky Linux.

Always exercise caution with these administrative tasks, especially when working in a single-user mode or root shell, as they allow you to make critical changes to your system.

You May Also Like

9 comments

Jalal Hajigholamali November 25, 2021 - 11:46 am

Hi,
Thanks a lot
Very useful article

Reply
BillBoss21 December 19, 2021 - 12:46 am

Failed to start Switch Root.

Give root password for maintenance (or press Control-D to continue):

Help me please

Reply
sk December 19, 2021 - 1:31 pm

What does it say when you enter the root user password?

Reply
Ros February 19, 2022 - 3:53 pm

I have the same problem.
It say:

Login incorrect.
Give root password for maintenance
(or press Control-D to continue):

Reply
sk February 19, 2022 - 7:50 pm

Hmmm… I haven’t had this issue in my test machine. I will try with another test machine.

Reply
john May 18, 2022 - 8:14 pm

Another way to change the root passwd or create one when Fedora gives you the option to create one on installation is to open a terminal and enter “sudo passwd root”. You will be asked to give your sudo password and then enter the new root password, and then enter it again. I have used this on several of the latest versions of Fedora, including 36.

Reply
Jessie May 27, 2023 - 1:28 am

Thanx. It’s an extremely useful info.

Reply
Fernando May 30, 2023 - 2:56 am

Now none of my passwords work. Thank you very much

Reply
sk May 30, 2023 - 11:23 am

It works for me. I tested these steps in my Fedora 38 system.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More