Friday, August 27, 2010

Forget root password of a Debian Machine & resetting it

I am writing this small post just because

  • i forgot the root password of my debian machine
  • didn’t find a through post that list all steps in one place and had to look at several ones at a time

The steps are as follows

I am quoting these lines from that post

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.

According to the above words, we should be ok and we have access to the file system. At this state you run the command “passwd” and enter the new password.

If it worked with you then Thanks to the editor. If you got some problems like me, then keep reading.

Problem 1

After editing grub line and add the “single” keyword at the end of that line. I got it loading well until i was prompted for the root password for maintenance and give the ability to skip but by then i will be leaving runlevel 1 and entering runlevel 2 getting login/password prompt i am trying to skip.

To solve this problem do the following:

  • Edit the grub line again and leave the keyword “single” there as before but add at the end as well these words “init=/bin/bash”
  • exit edit mode
  • press the button “b” while you have this modified grub line highlighted to start booting with this modified grub line

Voila, you have now access to shell as a root. run the command “passwd” and you should be fine entering the new desired password. If you got a problem, then continue reading.

Problem 2

Whenever i run the command “passwd” and re-enter the new password i get this error at the end

authentication token lock busy

If so, know that the problem is that you are accessing the system in read-only mode. In order to access it in read-write mode, do the following.

From the shell run this command

mount -o remount,rw /

after that run “passwd” command and this time you should have the ability to enter the new password

and live happily ever after

No comments: