Linux

Categorized | System, cli

Recover your lost root password in Linux

Once in a lifetime you might forget your root password. If that happens, reboot your distro and at the GRUB prompt press “e” to edit the first line. Make sure the new entry sais “linux single”. Press “b” to boot the new entry line. You’ll be thrown into single user mode and given a BASH prompt. Do a

cd /etc
nano passwd

Now see that line that sais

root:x:0:0:root:/root:/bin/bash

somewhere at the top of the file? Make it look like

root::0:0:root:/root:/bin/bash

by deleting the “x” between the two “:“. Save the file. Now open up the shadow file in nano:

nano shadow

Make the first line look like this:

root::::

by deleting every encrypted password. Save.
Reboot and log in as a normal user, then set a new root password:

su
passwd

Author Profile

T4L ;

Other posts by T4L

Author's web site



Are you satisfied with this blog?
Why not subscribe our RSS Feed? you will always get the latest post.


8 Comments

  1. petrescs

    Maybe I’m missing something, but as soon as one gets to cli prompt in single mode, they can simply use passwd command to set a new one.

    1
  2. T4L

    The rest of the tip is for people running older versions of Linux distributions. I - for example - still have a FC3 box laying around on pretty old hardware. Some people run even older Linux versions. The “edit your passwd file” part is for them.

    2
  3. T4L

    …not to say of user accounts that are not in the sudoers file and cannot therefore change a system password. No administrative rights.

    3
  4. rico

    in single user mode you are root.
    So no need to use sudo and there for no need to be in the sudoers file.

    Have you ever logged into single user mode?
    That last comment of yours amaze me if you ever did.

    4
  5. T4L

    @rico: you’re right, that sudoers reference slipped my mind. Somehow it made sense when I wrote it :))

    5
  6. Tux

    No need to reboot - after you’re done with runlevel one, you can just continue with the normal boot process (init n) where n is your default runlevel.

    6

  7. how delete the X from this root:x:0:0:root:/root:/bin/bash

    Please show me how to delete the X as you did
    please show step by step
    Thank you

    7

  8. i got it thnk you, how to do

    8

2 Trackback(s)

  1. 01 08 2009 : HowtoMatrix » Recover your lost root password in Linux
  2. 20 08 2010 : Como recuperar tu contraseña de root « programación, libertad e inspiración…

Leave A Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>