Take the 2-minute tour ×

If we don't know the root password and don't have root access to the machine, how can we change the root password?

share|improve this question
This is a often asked question, have a look at askubuntu.com/questions/24006/… –  Archemar Nov 17 at 12:25
See also: unix.stackexchange.com/a/168422/25985 –  goldilocks Nov 17 at 12:57

4 Answers 4

up vote 16 down vote accepted

Here are a few ways I can think of, from the least intrusive to the most intrusive.

Without Rebooting

With sudo: if you have sudo permissions to run passwd, you can do:

sudo passwd root

Enter your password, then enter a new password for root twice. Done.

Editing files: this works in the unlikely case you don't have full sudo access, but you do have access to edit /etc/{passwd,shadow}. Open /etc/shadow, either with sudoedit /etc/shadow, or with sudo $EDITOR /etc/shadow. Replace root's password field (all the random characters between the second and third colons :) with your own user's password field. Save. The local has the same password as you. Log in and change the password to something else.

These are the easy ones.

Reboot Required

Single User mode: This was just explained by Renan. It works if you can get to GRUB (or your boot loader) and you can edit the Linux command line. It doesn't work if you use Debian, Ubuntu, and some others. Some boot loader configurations require a password to do so, and you must know that to proceed. Without further ado:

  1. Reboot.
  2. Enter boot-time password, if any.
  3. Enter your boot loader's menu.
  4. If single user mode is available, select that (Debian calls it ‘Recovery mode’).
  5. If not, and you run GRUB:
    1. Highlight your normal boot option.
    2. Press e to enter edit mode. You may be asked for a GRUB password there.
    3. Highlight the line starting with kernel or linux.
    4. Press e.
    5. Add the word ‘single’ at the end. (don't forget to prepend a space!)
    6. Press Enter and boot the edited stanza. Some GRUBs use Ctrl-X, some use b. It says which one it is at the bottom of the screen.

Your system will boot up in single user mode. Some distributions won't ask you for a root password at this point (Debian and Debian-based ones do). You're root now. Change your password:

mount / -o remount,rw
passwd # Enter your new password twice at the prompts
mount / -o remount,ro
sync # some people sync multiple times. Do what pleases you.

and reboot, or, if you know your normal runlevel, say telinit 2 (or whatever it is).

Replacing init: superficially similar to the single user mode trick, with largely the same instructions, but requires much more prowess with the command line. You boot your kernel as above, but instead of single, you add init=/bin/sh. This will run /bin/sh in place of init, and will give you a very early shell with almost no amenities. At this point your aim is to:

  1. Mount the root volume.
  2. Get passwd running.
  3. Change your password with the passwd command.

Depending on your particular setup, these may be trivial (identical to the instructions for single user mode), or highly non-trivial: loading modules, initialising software RAID, opening encrypted volumes, starting LVM, et cetera. Without init, you aren't running dæmons or any other processes but /bin/sh and its children, so you're pretty literally on your own. You also don't have job control, so be careful what you type. One misplaced cat and you may have to reboot if you can't get out of it.

Rescue Disk: this one's easy. Boot a rescue disk of your choice. Mount your root filesystem. The process depends on how your volumes are layered, but eventually boils down to:

 # do some stuff to make your root volume available.
 # The rescue disk may, or may not do it automatically.
 mkdir /tmp/my-root
 mount /dev/$SOME_ROOT_DEV /tmp/my-root
 $EDITOR /tmp/my-root/etc/shadow
 # Follow the `/etc/shadow` editing instructions near the top
 cd /
 umount /tmp/my-root

Obviously, $SOME_ROOT_DEV is whatever block device name is assigned to your root filesystem by the rescue disk and $EDITOR is your favourite editor (which may have to be vi on the rescue system). After the reboot, allow the machine to boot normally; root's password will be that of your own user. Log in as root and change it immediately.

Other Ways

Obviously, there are countless variations to the above. They all boil down to two steps:

  1. Get root access to the computer (catch-22 — and the real trick)
  2. Change root's password somehow.
share|improve this answer
Anyway to do this remotely? Assuming that SSH got shutdown. –  CMCDragonkai Jun 11 at 9:19
Without SSH (or, presuming any of the other, scarily insecure methods like rsh or telnet), you don't have remote access to the machine, so you can't change the password. Unless of course the target computer has a known remotely exploitable issue which can help you somehow spawn a shell. The thought terrifies me more than a telnet daemon running on it. :) –  Alexios Jun 16 at 8:59
So I would have to physically teleport there to fix it? –  CMCDragonkai Jun 16 at 9:02
WRT "Change root's password somehow", see here: unix.stackexchange.com/a/168422/25985 –  goldilocks Nov 17 at 12:56

This should work on just about any distro, I think.

If you can access the root partition from another system, e.g. a live CD, you can as root from there edit /etc/shadow; first you have to chmod u+w shadow. Find the entry for root, it's probably the first one and looks something like this:


Erase everything between the first two colons so you end up with:


Then chmod u-w shadow. You can now reboot the system and root will have no password. You can just type root at the login prompt and it won't ask for one. You can then use passwd to set one.

To be extra careful:

  • Create a backup copy of /etc/shadow first.
  • Don't log in as anyone but root until you've set a new password. This is not critical, but guards against the theoretical possibility of unprivileged malware making some kind of hail mary pass ("Hey, maybe there's no root password..."). Kinda far-fetched IMO.
share|improve this answer
That will work, but boy does it make me *cringe* to remove the password on a root account. I take it Ubuntu doesn't drop you in a root shell in runlevel 1? Or wouldn't a better idea be to run passwd in a chroot environment from the live CD? –  SailorCire Nov 17 at 14:50
If you feel safer trying those other methods first, go ahead. But as long as you don't leave the system without a root password, this should be fine. There wouldn't be a point in malware that tried to exploit this, because if it were running at boot, it already has root privileges anyway. So don't log in as anyone else first, I guess (might be a problem on systems that don't allow root in via the display manager, unless you can switch to console). Even then it seems pretty unlikely. –  goldilocks Nov 17 at 15:03
@SailorCire ^^^ –  goldilocks Nov 17 at 15:10
I'm very doubtful about the malware possibility as well. However, the idea behind what I suggested is that it prohibits the "Oh I'll change it later, because it works now" type of mentality that a lot of us fall in to. –  SailorCire Nov 17 at 17:59

Judging from the tags I take that you're using RHEL, but this solution should work equally well for all distros.

If the root password is forgotten, you can boot in single-user mode and use this to change the password. This approach is described in the Red Hat step-by-step guide:

  1. Enter the GRUB menu and press e .
  2. Choose the line that begin with kernel, press e again.
  3. On the end of this line, put single. Then press ENTER and boot from it.

You will eventually get to a prompt where you can type passwd root and change the password. Then type reboot to reboot the system.

share|improve this answer
This will work only if you don't have any boot passwd. –  pradeepchhetri Apr 7 '12 at 6:33
And if you're not using /sbin/sulogin for single-user shell (it will prompt for root's password). –  James O'Gorman Apr 7 '12 at 9:52

I use Clonezilla for a lot of sysadmin-y rescue tasks. Clonezilla is a free imaging software which is awesome in itself. It also features a shell and mini-linux kernel which lets you do a LOT of things, including something like resetting a root password. It's really awesome and is a good tool to get familiar with!

Clonezilla: http://clonezilla.org

My blog and videos on how to use it to reset root password: http://geekswing.com/geek/resetting-root-password-on-a-linux-system-using-clonezilla/

share|improve this answer

Your Answer


