Monday 9 August 2010

Locked out of Ubuntu?

You may be faced with a situation similar to one in which I found myself, in which case here's the story of my escapade. I recently dug up an old laptop which had Ubuntu installed on it, and I had no idea what I set up as the password for my user account on the system. Before formatting the entire hard drive, I wanted to check if I had any valuable data on the hard drive, so my options were:

- Slave the IDE hard drive on a system that can read ext3
- Use a linux boot CD to see if I could mount the hard drive
- Attempt to boot into bash as root

I chose to go for the option as it was the easiest to do, without having to get up from my seat :)

---------------------------------------------------------------------------------------------------------------------------------------- Note:
By default, Ubuntu installs a recovery mode in the GRUB menu, if thats there, then you can enter the recovery console (which puts you as the root user) and use the passwd command to change any users password.

----------------------------------------------------------------------------------------------------------------------------------------

Unfortunately I didnt have that option as I took it out as a security measure. Little know to some people is that the grub boot menu can be edited in most cases by pressing 'e' whilst the menu is showing. (You may need to press the escape key to enable this feature.

So highlight the kernal you want to edit, and press 'e', highlight the line that begins with the word kernal and press 'e' again.


Now you need to edit the end of this line and delete the 'ro quiet splash' part and replace it with 'rw init=/bin/bash'. This will boot the kernal straight into bash as root.


Save this by pressing escape and it should take you back to the previous screen. Press 'b' to boot into the kernal, for which you have just edited the settings for.

From here you should be logged into a shell with root access. To change any users password, simply use the passwd command.

passwd [username]

And you have regained control of your account again. Don't forget to change the boot settings back to what they were.

Happy hacking :)