forgot root password or reset root password in Debian

There are times for system administrators they might have forgot their debian machine root password and they want to reset this password.We will see the available options.

There are various methods available for resetting a root password.

Boot debian linux into single-user mode
Boot using a boot disk (like knoppix,gnoppix) and edit the password file
Mount the drive on another computer and edit the password file

It is possible to boot a system and log on to the root account without knowing the root password as long as one has access to the console keyboard.

This is a procedure which requires no external boot disks and no change in BIOS boot settings. Here, “Linux” is the label for booting the Linux kernel in the default Debian install.

Solution 1

At the lilo boot screen, as soon as boot: appears (you must press a shift key at this point on some systems to prevent automatic booting and when lilo uses the framebuffer you have to press TAB to see the options you type), enter:

boot: Linux init=/bin/sh

This causes the system to boot the kernel and run /bin/sh instead of its standard init. Now you have gained root privileges and a root shell. Since / is currently mounted read-only and many disk partitions have not been mounted yet, you must do the following to have a reasonably functioning system.

# mount -n -o remount,rw /

# mount -avt nonfs,noproc,nosmbfs

# cd /etc

# vi passwd

# vi shadow

(If the second data field in /etc/passwd is “x” for every username, your system uses shadow passwords, and you must edit /etc/shadow.) To disable the root password, edit the second data field in the password file so that it is empty. Now the system can be rebooted and you can log on as root without a password. When booting into runlevel 1, Debian (at least after Potato) requires a password, which some older distributions did not.

It is a good idea to have a minimal editor in /bin/ in case /usr/ is not accessible.Also consider installing the sash package. When the system becomes unbootable, execute

boot: Linux init=/bin/sash

sash serves as an interactive substitute for sh even when /bin/sh is unusable. It’s statically linked, and includes many standard utilities as built-ins.

Solution 2

Boot from any emergency boot/root disk set. If /dev/hda3 is the original root partition, the following will let one edit the password file just as easily as the above.

# mkdir recovery

# mount /dev/hda3 recovery

# cd recovery/etc

# vi shadow

# vi passwd

Scroll down to the line containing the root user’s information, which looks something like

root:weeWRSF!sfDFs:12581:0:99999:7:::

Delete everything between the first and second colons, so that the line looks like

root::12581:0:99999:7:::

Save the file and exit your editor.Type cd to return to your home directory.

Type umount mountplace to unmount the partition.

#unmount /dev/hda3 recovery

Type reboot to reboot your system

The advantage of this approach over the previous method is one does not need to know the lilo password . But to use it one must be able to access the BIOS setup to allow the system to boot from floppy disk or CD, if that is not already set.

Solution 3

Reseting passwords by mounting on another system and editing the password file is bit more work need to be done.first you need to Shut down the machine after backing up all important data.Now remove you machine hard disk and connect this hard disk as slave drive for another machine(this should be linux OS) and boot this machine.Once the system finishes booting, mount the slave drive’s root partition and edit the password file.If /dev/hda3 is the original root partition, the following will let one edit the password file just as easily as the above.

# mkdir recovery

# mount /dev/hda3 recovery

# cd recovery/etc

# vi shadow

# vi passwd

Scroll down to the line containing the root user’s information, which looks something like

root:weeWRSF!sfDFs:12581:0:99999:7:::

Delete everything between the first and second colons, so that the line looks like

root::12581:0:99999:7:::

Save the file and exit your editor.Type cd to return to your home directory.

Type umount mountplace to unmount the partition.

#unmount /dev/hda3 recovery

Type reboot to reboot your system

If you want to prevent others from resetting your root password you can use two options first one is protect your bootloader with password i.e your GRUB or LILO boot loaders and second one is protect BIOS with password.

Sponsored Link

16 thoughts on “forgot root password or reset root password in Debian

  1. Solution 4
    boot with livecd (i’m using slackware install)
    mkdir /d
    mount /dev/hda1 /d
    chroot /d
    passwd (or passwd root)
    type your new password
    press Ctrl+Alt+Delete and enjoy

  2. I know I’m just one of those newbie in linux and you don’t have time to update the web page every-time.please show me how to do it with grub as it is the most default bootloader.

    thanks for hearing me

  3. Yes you can do it from grub as well:

    1. Select the appropriate entry in the grub menu and press ‘e’
    2. Select the kernel … line and press ‘e’
    3. Append ‘init=/bin/bash’ at the end of line
    4. Press ‘b’ to boot

    Then you will need to remount the system as rw and use the passwd command to change the pass

  4. Thanks Theo… I’ve added the mount command for the likes of me:

    mount -n -o remount,rw /

  5. I have mac os x my girl friend mistakely change the user name and password I did not know where i put my installation disc pls. help

  6. Thanks so much! Helped me out on an old server where the former admin forgot the password or it was changed somehow.

  7. Also, I was just able to use ‘passwd root’ when I got root access using Solution 1, didn’t have to edit any files.

  8. For Ubuntu, if you are a member of the admin group, you can simply type:

    sudo passwd

    Enter your user password and then it will allow you to change the “UNIX” password… su.

  9. What Erica just said is valid for more then Ubuntu.. is valid for more distributions.

    LX Debian

  10. I am using Ubuntu9.4. When I boot it with init=/bin/bash, It comes to root@none:/ and hangs.

    need help.

  11. I have a Lenny install where there is an x in the second data field (passwd) but no shadow file. There is a backup of the shadow file in var/backup/. I don’t know if this is from previous etch install or what? Does Lenny use shadow anymore? Same name?

  12. It’s very easy to reset the root password in the case of 32 bit version.

    But I would like to know, how to reset the root password of a Debian 64 bit machine? I’ve a rescue CD.

  13. Hi Guys,

    I tried solution 1 because I don’t have a recovery cd or another system: Here’s the problem.

    When I do – “# mount -avt nonfs,noproc,nosmbfs” but I get a line returned saying “nothing was mounted”

    What can I do?

  14. thank you!
    this side helped me a lot. I had installed debian on a mac with powerpc processer and yaboot ages ago and forgot my user and root password.
    i used a combination of solution 1 and 2:
    1) boot: Linux init=/bin/bash
    2) mount -n -o remount,rw /
    3) vi shadow
    Scroll down to the line containing the root user’s information, which looks something like
    root:weeWRSF!sfDFs:12581:0:99999:7:::
    Delete everything between the first and second colons, so that the line looks like
    root::12581:0:99999:7:::
    Save the file and exit your editor.
    4) exit the console
    5) i got some kernel panic and had to press the on/off button on the box for soem secounds to get the computer switched off. then i started the computer again.
    6) after the graphical logon screen appeard pess ctrl + alt + f1 to change to a text console
    7) logan as root – you should now not need a password.
    8) change the user password by the ‘passwd user’ commad
    9) chnage to the graphical consol by ctrl + alt + f7
    10) logon with that user and then new password

Leave a comment

Your email address will not be published. Required fields are marked *