2018-03-27 03:59:37 +00:00
= How to Reset the root Password
2022-12-17 07:24:27 +00:00
The Fedora docs team
2022-12-19 19:35:43 +00:00
:revnumber: F36
2022-12-17 07:24:27 +00:00
:revdate: 2022-01-10
:category: Administration
:tags: Password
2017-10-26 21:20:01 +00:00
2022-12-17 07:24:27 +00:00
[abstract]
A root password may be set up while installing Fedora Linux, although it is now suggested to leave the root account locked and use `sudo`. This article describes how to proceed if you have used a root password, but for some reason you can no longer access it.
2023-08-18 07:25:35 +00:00
2019-03-20 22:42:41 +00:00
2022-01-25 01:42:08 +00:00
There are two common methods to reset the root password if it is forgotten or lost.
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
* In Rescue Mode
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
* Using a Fedora Live Media (USB/DVD/CD)
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
== How to reset the root password in Rescue Mode
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
[NOTE]
====
2022-01-25 01:42:08 +00:00
Changing passwords as root will not prompt for the old password.
2018-03-27 03:59:37 +00:00
====
2017-10-26 21:20:01 +00:00
2023-08-18 06:41:39 +00:00
While booting the system, the xref:grub2-bootloader.adoc[GRUB2] menu will be displayed. To boot the system into rescue mode using `bash` follow these steps:
2017-10-26 21:20:01 +00:00
2022-01-25 01:42:08 +00:00
. Select the boot entry you wish to edit with the arrow keys.
2017-10-26 21:20:01 +00:00
2024-09-09 18:40:35 +00:00
. Select the entry you wish to edit by pressing *e*.
2017-10-26 21:20:01 +00:00
2023-01-02 16:12:30 +00:00
. Use the arrow keys to go to select the line beginning with `linux`, `linux16`, or `linuxefi`.
2017-10-26 21:20:01 +00:00
2022-01-25 01:42:08 +00:00
. Go the the end of that line and include a space and the following `rw init=/bin/bash`.
2022-12-19 19:35:43 +00:00
+
2023-08-18 06:41:39 +00:00
[NOTE]
====
If your disk is encrypted, you may need to add `plymouth.enable=0`[NOTE]
====
2022-01-25 01:42:08 +00:00
. Press *Ctrl-x* or *F10* to boot the entry
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
. Run the command:
+
[source,bash]
----
passwd
----
+
2022-01-25 01:42:08 +00:00
You will be prompted to enter the new root password twice.
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
. Restore the SELinux context and permissions with:
+
[source,bash]
----
touch /.autorelabel
----
+
[WARNING]
====
If you do not restore the SELinux permissions, the boot process may fail.
You may have to do a hard-reboot and start back at step 1.
====
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
. Reboot the machine with:
+
[source,bash]
----
/sbin/reboot -f
----
2017-10-26 21:20:01 +00:00
2022-01-28 03:45:55 +00:00
The system may take a moment to boot while SELinux relabels its permissions on the filesystem.
2018-03-27 03:59:37 +00:00
If you see the Plymouth boot screen you can press the `ESC` key on your keyboard to view the SELinux progress.
2022-12-19 19:35:43 +00:00
2018-03-27 03:59:37 +00:00
Once it is complete, your system is ready and your root password has been successfully changed.
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
[[sect-reset-password-using-the-fedora-live-media]]
== How to reset the root password with a Fedora Live Media
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
[NOTE]
====
2022-12-19 19:35:43 +00:00
To _download_ and create a live USB of Fedora Workstation, follow the instructions on the xref:creating-and-using-a-live-installation-image.adoc[Fedora USB Live Media Quick Doc].
__For additional information__, specifically about live media using BTRFS, see also
2023-08-18 08:51:01 +00:00
xref:grub2-bootloader.adoc#_restoring_the_bootloader_using_the_live_disk[Restoring the bootloader using the Live disk]
2018-03-27 03:59:37 +00:00
====
2017-10-26 21:20:01 +00:00
2022-01-25 01:42:08 +00:00
. Boot the Live installation media and choose `Try Fedora`.
2017-10-26 21:20:01 +00:00
2022-01-25 01:42:08 +00:00
. From the desktop, open a terminal and switch to root using `su` (the system will not ask for a password).
2017-10-26 21:20:01 +00:00
2022-01-25 01:42:08 +00:00
. To view your hard drive device nodes, enter `df -H` into the terminal.
2020-04-18 21:27:08 +00:00
For this example we will use `/dev/sda1` for the `/boot` partition and `/dev/sda2` for the root `/` partition.
2018-03-27 03:59:37 +00:00
+
If you are using LVM partitions, type: `sudo lvscan` and note the `/dev` path of your root partition.
For this example we will use `/dev/fedora/root`.
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
. Create a directory for the mount point (use the `-p` option to create subdirectories):
+
[source,bash]
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
----
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
mkdir -p /mnt/sysimage/boot
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
----
2017-10-26 21:20:01 +00:00
2018-03-27 03:59:37 +00:00
. Mount the `/` (root) partition (be sure to use the actual device node or LVM path of your root `/` partition):
+
To mount root on a *standard partition* scheme enter:
+
[source,bash]
----
2019-03-20 22:42:41 +00:00
mount /dev/sda2 /mnt/sysimage
2018-03-27 03:59:37 +00:00
----
+
To mount root on an *LVM partition* scheme enter:
+
[source,bash]
----
mount /dev/fedora/root /mnt/sysimage
----
. Continue the process by mounting `/boot`, `proc`, `/dev`, and `/run` with:
+
[source,bash]
----
mount /dev/sda1 /mnt/sysimage/boot
mount -t proc none /mnt/sysimage/proc
mount -o bind /dev /mnt/sysimage/dev
mount -o bind /run /mnt/sysimage/run
----
. `chroot` to the mounted root partition with:
+
[source,bash]
----
chroot /mnt/sysimage /bin/bash
----
. Change the root password:
+
[source,bash]
----
passwd
----
. Exit out of chroot with:
+
[source,bash]
----
exit
----
+
and exit out of the terminal.
. Reboot your system and boot from the hard drive.
Congratulations, your root password has been successfully changed.
[[sect-additional-troubleshooting]]
== Additional Troubleshooting
. If you cannot enter rescue mode because you forgot the Firmware/BIOS password here are some options:
.. Refer to your computer's documentation for instructions on resetting the Firmware/BIOS password in CMOS memory.
.. Temporarily move the system hard disk to another machine, and follow the procedures above to reset the root password.
2019-03-22 15:20:33 +00:00
. If you have set a password for your boot loader, refer to xref:creating-and-using-a-live-installation-image.adoc[Creating and Using a Live Installation Image].
2018-03-27 03:59:37 +00:00
2019-03-20 22:42:41 +00:00
. If you want to reset the boot loader password, refer to the instructions on how to link:++https://fedoraproject.org/wiki/Reset_Bootloader_Password++[Reset the Bootloader Password].