Debian/Ubuntu Tips & Tricks

Debian/Ubuntu Tips & Tricks

Debuntu.org: .deb packages, Unix/Linux Tutorials and Articles.

Sponsors

User login

Syndicate

Syndicate content

Tips Bucket

Who's online

There are currently 0 users and 40 guests online.

How-To: Recover root password under linux with single user mode

It happens sometime that you can't remember root password. On Linux, recovering root password can be done by booting Linux under a specific mode: single user mode.
This tutorial will show how to boot Linux in single user mode when using GRUB and finally how to change root password.

During normal usage, a Linux OS runs under runlevels between 2 and 5 which corresponds to various multi-user modes. Booting Linux under runlevel 1 will allow one to enter into a specific mode, single user mode. Under such a level, you directly get a root prompt. From there, changing root password is a piece of cake.

1. Entering runlevel 1

Some Linux distribution, such as Ubuntu for instance, offer a specific boot menu entry where it is stated "Recovery Mode" or "Single-User Mode". If this is your case, selecting this menu entry will boot your machine into single user mode, you can carry on with the next part. If not, you might want to read this part.

Using GRUB, you can manually edit the proposed menu entry at boot time. To do so, when GRUB is presenting the menu list (you might need to press ESC first), follow those instructions:

  • use the arrows to select the boot entry you want to modify.
  • press e to edit the entry
  • use the arrows to go to kernel line
  • press e to edit this entry
  • at the end of the line add the word single
  • press ESC to go back to the parent menu
  • press b to boot this kernel

The kernel should be booting as usual (except for the graphical splash screen you might be used to), and you will finally get a root prompt (sh#).

Here we are, we have gained root access to the filesystem, let's finally change the password.

2. Changing root password

As root, changing password does not ask for your old password, therefore running the command:

# passwd

will prompt you for your new password and will ask you to confirm it to make sure there is no typo.

That's it, you can now reboot your box and gain root access again

How it worked for me...

I am running Ubuntu 9.10 on an old Pentium 3 500 MHz, 500 MB machine. It runs ok as long as only 1 window is open. Nonetheless, here is how the sequence worked for my machine:

1) while the system is booting up, wait until the bios etc. completes - BUT GET READY! (you may have to do this twice since the GRUB message about ESC lasts ~ 1/2 sec.)

2) at the GRUB message HIT 'ESC' IMMEDIATELY

3) Follow the above sequence up to and including writing the word 'single' at the end of the command line that appears.

4) hit 'ESC' to return to the _previous_ screen. That is the screen where you selected to edit the kernel. Now type 'b'.

5) a new screen appears. select "Drop to the root command line."

6) you should now have a single-user prompt where you can type 'passwd'. That's it.

Reboot into normal mode and now you have root access to your machine.

:p You can change the Root PW for Any Linux Distro

If you have a Boot CD for that Distro simply boot it into Recovery Mode; if you can't figure that out then stick with Windows (which has an unprotected default Admin acct on all versions since Windows 95 btw...)

Same with Solaris and AIX - both those versions of Unix allow for disaster-level 'root' password recovery if you can do these 2 things:

1) Prove you are who you are supposed to be by registration verification with the Vendor, and
2) Know the exact (usually long) Disk/Volume/Directory/Path/ to the slice which has the passwd file itself.

Not impossible; but not designed to be easy; AIX for example, is a C2-level rated secure computing platform - you aren't supposed to walk upto to it and become root just because you can touch the physical box. Linux, any flavor (Fedora/RedHat/Debian) becoming root is pretty straight-forward:

1) Get a recovery CD (usually any installation CD will do it)
2) Boot the system off the CD
3) Hit Ctrl F2 or Ctl F3 -- get a shell (you are not in single user mode you are in the Highest level: Creator mode -- in this mode you are not playing at being GOD, you are GOD (root pretends to be GOD, it isn't)
4) Mount the slice that has the passwd file (hopefully the volume isn't encrypted (all mine are...)

5) vi /mount/path/etc/shadow (on the line with root - usually something like this:
root:<--- Edit this part Out --->:14685:0:99999:7:::

Edit the section between the 1st two colons (the section indicated by <--- Edit this part Out ---> ...))

6) Reboot without CD

-Sx-

It looks like a security fail

If I want to get a pass from anybody, I only need to do this, come on, this is so easy, not even in windows is that easy to get a pass.

Well, here it goes for

Well, here it goes for windows password: http://home.eunet.no/~pnordahl/ntpasswd/ ....
Debuntu

If you get asked for the

If you get asked for the root password when entering single user mode use 'init=/bin/bash' on the kernel append line which should boot the machine into a bash console where you can get read/write access to your /etc/shadow file. You can then either run `passwd` or edit the shadow file directly to put in an empty string. This allows you to reboot the machine into its normal environment and login as root leaving the password blank and then run the `passwd` program to set the root password. This should really only be done when the machine is detached from any networks.
Chris
Spanish Translation

And fedora I did using following steps

I got it working after following some more steps and have blogged it here:

http://digitalpbk.blogspot.com/2009/03/reset-root-password-linux-fedora-debian.html

Easier method

You do not need to be in single user mode.

It is much MUCH simpler to reset this, I will tell you how.

Open a terminal program (command line, X terminal, whatever you want.)

type:

sudo su

You know are acting as 'root' of your system.

now type:

passwd

it will say: "Now changing password for root" or whatever. Just follow your computer's directions from here.

Any questions to emilio140790@hotmail.com for I will not look at this message place again (probably)

This is true, but this

This is true, but this suppose that you have a sudo account in the first place.
Debuntu

In what fucking distro can

In what fucking distro can you do this?

This works under Redhat but

This works under Redhat but NOT under ubuntu feisty.

Feisty will ask you for the root password when you try to boot into single user mode, as will SuSE and Solaris for that matter.

I don't know if previous version of ubuntu or debian behave this way or not.

This is why it is important to ALWAYS have a grub password when using Redhat/Fedora.

alternative

If you get asked for the root password when entering single user mode use 'init=/bin/bash' on the kernel append line which should boot the machine into a bash console where you can get read/write access to your /etc/shadow file. You can then either run `passwd` or edit the shadow file directly to put in an empty string. This allows you to reboot the machine into its normal environment and login as root leaving the password blank and then run the `passwd` program to set the root password. This should really only be done when the machine is detached from any networks.

It works with Ubuntu Feisty

> Feisty will ask you for the root password when you try to boot into single user mode,
I just tried it out. Ubuntu Feisty does not ask for the root password. But Debian Etch does.
However, as long as it is not encrypted, you can edit /etc/shadow with a live distri.

Use encryption. My Debian

Use encryption. My Debian Etch has one aes-encrypted Partition. This is a container for all the partitions, including swap. Only /boot with grub and the kernel is unencrypted.
When starting I am asked for the password. That's it.
Of cause, my usual identity does not have sudo-right. I am not ubuntu.

Maybe someone changes my kernel. I should calculate a sha1 right after after startup. But that's paranoid.

You can do this on Ubuntu at

You can do this on Ubuntu at least.
I believe you can to this on many different debian based distro, as well as many different other distro usig Grub.
Debuntu