Linux How to reset a root password on Fedora

A system administrator can easily reset a password for a user that has forgotten their password. But what happens if the system administrator forgets the root password? This guide will show you how to reset a lost or forgotten root password. Note that to reset the root password, you need to have physical access to the machine in order to reboot and to access GRUB settings. Additionally, if the system is encrypted, you will also need to know the LUKS passphrase.

Edit the GRUB settings

First you need to interrupt the boot process. So you’ll need to turn on the system or restart, if it’s already powered on. The first step is tricky because the grub menu tends to flash by very quickly on the screen.

Press E on your keyboard when you see the GRUB menu:

After pressing ‘e’ the following screen is shown:

Use your arrow keys to move the the linux16 line.

Using your del key or backspace key, remove rhgb quiet and replace with the following.

rd.break enforcing=0

After editing the lines, Press Ctrl-x to start the system. If the system is encrypted, you will be prompted for the LUKS passphase here.

Note: Setting enforcing=0, avoids performing a complete system SELinux relabeling. Once the system is rebooted,  restore the correct SELinux context for the /etc/shadow file. (this is explained a little further in this process)

Mounting the filesystem

The system will now be in emergency mode. Remount the hard drive with read-write access:

# mount –o remount,rw /sysroot

Password Change

Run chroot to access the system.

# chroot /sysroot

You can now change the root password.

# passwd

Type the new root password twice when prompted. If you are successful, you should see a message that all authentication tokens updated successfully.

Type exit, twice to reboot the system.

Log in as root and restore the SELinux label to the /etc/shadow file.

# restorecon -v /etc/shadow

Turn SELinux back to enforcing mode.

# setenforce 1
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
watchdog How to restart a process out of crontab on a Linux/Unix
Viewed 6049 times since Tue, Jul 31, 2018
How to encrypt a partition with DM-Crypt LUKS on Linux
Viewed 8239 times since Fri, Jul 13, 2018
8 Vim Tips And Tricks That Will Make You A Pro User
Viewed 2972 times since Fri, Apr 19, 2019
Extending Linux LVM partitions script
Viewed 6432 times since Wed, Feb 6, 2019
How to run command or code in parallel in bash shell under Linux or Unix
Viewed 3266 times since Tue, Aug 6, 2019
Method 2 – Use shell scripts How to install yum cron on a CentOS/RHEL 6.x/7.x
Viewed 4171 times since Tue, Dec 4, 2018
HowTo: The Ultimate Logrotate Command Tutorial with 10 Examples
Viewed 5270 times since Fri, Nov 30, 2018
chrt command: Set / Manipulate Real Time Attributes of a Linux Process
Viewed 11076 times since Mon, Feb 17, 2020
RHEL: Handling SCSI disks
Viewed 12487 times since Sun, May 27, 2018
Linux – How to check the exit status of several piped commands
Viewed 2979 times since Wed, Jul 25, 2018