Otto background

Linux Hack of the Week #11 - Reset Lost Root Password

We’ve all been in this place: you can’t log in to one of your Linux boxes, and you’re not sure how to proceed. Although there are many reasons this might happen, it could be because your old admins left without sharing the password, you are hacking a machine, or you simply typo’d something. Actually, forget that I said you were hacking a machine. Moving on…

So, how do we reset a lost root password? For this example, I will use Fedora 28, but the process is similar, if not the same, on most flavors of unix.

Step 1: Reboot and edit

Reboot the machine and interrupt the grub boot process. Navigate to your kernel and select “e” to edit the line:

Find the line that begins with linux16 and go to the end of the line. Add “rw init=/bin/bash” to the line. I prefer to also remove the option “quiet” to get more verbose messaging, but that is a personal preference. When finished editing, hit CTRL-X to boot:

Step 2: Everything works as planned

If everything is working correctly you can now simply run passwd to supply a new password:

At this point you will have to power cycle the box and log in as usual. In the case that passwd did not work, continue on to the next step.

Step 3: The hard way

If things didn't go as planned the next step shows you how to edit the shadow file to blank out root’s password. Be careful, as you are now editing a tricky file. Edit /etc/shadow:

You now need to delete the letters between the first and second colon. Save the changes, and reboot:

DANGER, WILL ROBINSON!

Your password for root is now blank. Reboot into runlevel 1 and change the password immediately. If you are not on the network you can reboot normally, login as root and run passwd. Otherwise, enter the grub edit screen and add a 1 to the end of your kernel line, similar to before. This will point in to single user mode with no network:

When the OS boots up simply hit enter and type passwd:

Now you have reset your password and you are ready to continue on to your default run level.

Reset lost root password takeaway

We have all had to do this on our Linux boxes once or twice, and hopefully, this will save you a few minutes of googling.


Automox for Easy IT Operations

Automox is the cloud-native IT operations platform for modern organizations. It makes it easy to keep every endpoint automatically configured, patched, and secured – anywhere in the world. With the push of a button, IT admins can fix critical vulnerabilities faster, slash cost and complexity, and win back hours in their day. 

Grab your free trial of Automox and join thousands of companies transforming IT operations into a strategic business driver.

Dive deeper into this topic

loading...