Ubuntu hacking: back to the university time

Screen Shot 2015-02-09 at 14.27.46

Sometimes happens, for one reason or another, you lost the root password for your Ubuntu Server. What the hell? Yes, this is the situation. The reasons could be many and disparate like

  • you just don’t remember the infinitely complicate password you’ve set
  • you just don’t remember the infinitely easy password you’ve set
  • someone left the company and brought all the secrets with him (this is the case)
  • etc

However, we are not here discussing about what happened but about how to reconquer our server!
So, let’s start!

So, this is the current situation:

  • Ubuntu Server 12.04 LTS x86_64
  • no root password
  • automatically logged in with the user wannabe

Linux Grub, similar to the one in the example

There are different ways to hack sorry, recover 🙂 a root password in this situation.
I’ll suddenly adopt our way that worked perfectly.
This is my way but, as said, there are different ways based on the OS version, grub version, architecture etc..

  1. Reboot the server
  2. Press SHIFT to get the grub prompt
  3. Select your image (Ubuntu, bla bla bla), mine is the first one, not the recovery mode but the default one
  4. Press Fn + e (or just e) to edit the boot configuration for that image
  5. My penultimate row reports the write “[…] ro quiet splash”
    this means that the in this phase of the boot the filesystem is running in read-only mode and the screen will show you the boot splash screen
  6. Once located this line, we’ll change ro to rw (read-write mode)
  7. Then we’ll add init=/bin/bash after rw to tell we want to load the bash terminal on the boot
    by default the first user’s account is a root account, so if we succeed to load the bash we’ll already reasonably be root
  8. Press enter to push quiet splash to the new line, then press CTRL + X to save and reboot

Grub boot editor similar to the one in the example

The system will now load the bash with the root account ready to be used
Let’s change now the root password

root@ubuntu:/# passwd root
Changing password for user root.
New UNIX password:

Done, we set up the new root password. We can now reboot the system and easily login in as root.

Many other information are available at this address