How to Recover Linux Root Password

Forgetting the root password on a machine you own is one of those problems that feels much worse than it is. There is no recovery email, no reset link, and if you have inherited a server from someone who left, no one to ask. What there is, on any machine you can get to the console of, is a way straight in.

There are several methods. This is the one I keep coming back to, because it needs nothing but the boot menu and it has worked on every distribution I have thrown it at.

Why this works at all

The trick is single user mode. Boot Linux normally and it starts the full set of services and drops you at a login prompt. Boot it into single user mode and it brings up a minimal system with a root shell, and it does that before anything gets around to asking who you are.

No password is requested because nothing that would ask has started yet. Once you have that shell you are root, and resetting the password is an ordinary command.

Before you start

  • Save and close all your applications if you have opened already for safe data before reboot the machine.
  • Softly reboot your desktop client or server and wait for appearing a GRUB loader appearing.
  • When grub loader will be appeared, press “e” to edit into grub loader

Timing is the fiddly part. The boot menu is often set to move on after a couple of seconds, and on a server with a slow console you can miss it entirely. Watching from the moment the machine restarts, rather than wandering off and coming back, saves a lot of repeated reboots.

GNU Grub
GNU Grub

Editing the boot entry

  • Press arrow key and point to kernel line and then press “e” to edit into kernel

You are editing this boot only. Nothing here is written to disk, so a mistake costs you a reboot and nothing else. That is worth knowing, because it makes the whole procedure a lot less nerve-wracking the first time.

Kernel Grub
Kernel Grub

  • After that at the end of the kernel line and type “single” (without quotes) after give single space as shown below in the screenshot. and press “Enter” now.

That single word is the entire change. It tells the kernel which target to bring up, and everything else about the boot stays as it was.

Add Value in Kernel
Add Value in Kernel

  • Press “b” to boot after changes

Boot After Change
Boot After Change

Resetting the password

  • Now you will get the root prompt without asking password

Root Prompt
Root Prompt

  • Reset the “root” password now.

Enable Root Password
Enable Root Password

Set the new password, then reboot normally and log in with it. The edit you made to the boot entry was never saved, so the next boot is the ordinary one.

Notes and differences between systems

The screenshots above come from a GRUB legacy menu. The idea is identical on newer systems but the keys and the layout are not always the same, so treat the exact keypresses as a guide rather than gospel and read what your own boot screen tells you. The menu itself usually lists the keys along the bottom.

You may also find the root filesystem comes up read only, depending on the system. If the password change refuses to save, that is very often why, and remounting it writable before trying again sorts it.

The part nobody enjoys hearing

Read back what you just did. Anyone who can reach that boot menu can become root on the machine, and it takes about a minute. No password needed at any point.

That is not a bug, it is how physical access has always worked on almost every operating system. But it is worth being honest about what it means. Console access equals root access, and that applies to a laptop left in a hotel room, a server in a rack somebody else has the key to, and a virtual machine whose console is exposed in a hypervisor panel to more people than you think.

If that matters for a particular machine, the two things that actually help are a password on the bootloader, which stops the menu being edited, and full disk encryption, which stops the drive being read at all if someone simply takes it. Neither is much work to set up, and one afternoon spent on them is worth more than any amount of tightening up password policy on the login prompt.

Asif Khan

Asif Khan

DevOps, Linux, and cloud engineer with over a decade of hands-on experience. I build infrastructure for uptime and automate operations so problems get handled before anyone gets paged. My focus is automation, security, and systems built to survive failure, using Infrastructure as Code, CI/CD, containers, monitoring, and cloud platforms instead of manual fixes. This blog is where I write down what worked, and just as often what didn't the first time around. Real tutorials you can run yourself, troubleshooting notes pulled from actual outages, and the kind of detail you only get once you've hit the problem firsthand. If you're trying to get Linux, DevOps, and cloud infrastructure to behave, that's what you'll find here: reproducible solutions you can understand, test, and apply in your own environment.