Replacing a forgotten root password in Fedora 15

At school, one of the classes I teach is the Linux class. In this class, we use Fedora 15. One of my students had forgotten the root password of his machine, and despite trying everything he could think of, he wasn’t able to guess what he had set the password to. He came to me looking for a way to reset the password.

The easiest way to do this is to boot into single-user mode. In single-user mode, you don’t need to log in; you’re automatically logged in to the root account. From there, you just need to run the “passwd” command, and you can set a new password for root.

It was a little more difficult than I expected. When Fedora 15 is installed, by default it installs the GRUB bootloader. If we have a choice of more than one operating system to boot into, the Fedora installation gives us a few seconds to select which one. During these few seconds, we can stop the boot process, then tell GRUB that we want to enter single-user mode (via a Linux kernel command-line argument), and away we go. However, if we only have a single OS on the computer, as was the case for my student, GRUB boots immediately into Linux, and we don’t have a chance to modify the kernel arguments. I knew there was some way to stop the boot, and after a little googling, I found the answer. I thought it was worth a blog post in case anyone else runs into this situation.

Short answer: hold down the shift key as the computer is booting, then GRUB will allow you to specify single user mode.

Here’s the longer answer.

Turn on the computer, and as the computer is booting, press and hold the shift key. If you time it right (if you press and hold too early, GRUB won’t recognize the keypress), you will see the following screen:

Initial GRUB screen

That’s GRUB. OK, we want to edit the kernel command-line arguments (you can find a complete list of them here), so at this point press the “a” key. You’ll go into a screen that allows you to edit the arguments:

Editing the kernel parameters

To enter single-user mode, you just need to append an “S” to the end of the command line, being sure to leave a space between the previous last argument and the S. See the screenshot below for what it should look like.

After adding the single-user kernel parameter

Once you’ve got that, just press the Enter key, and you’ll boot into single-user mode (also known as rescue mode — because it will rescue you from the forgotten root password!). You’ll be at the console, not the GUI, and your screen will look like this.

In single-user mode

Now, we can run the “passwd” command, and enter in the new password. The password won’t be displayed on the screen, but we’ll be asked to enter it twice, to make sure we didn’t make a typing mistake. After running the command, your screen will look like:

After changing the password

Once that’s done, you’ll be able to use your new password to log in to your root account. Now, just type CTRL-D, and the system will boot as normal, and away you go!