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)
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
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..
- Reboot the server
- Press SHIFT to get the grub prompt
- Select your image (Ubuntu, bla bla bla), mine is the first one, not the recovery mode but the default one
- Press Fn + e (or just e) to edit the boot configuration for that image
- 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
- Once located this line, we’ll change ro to rw (read-write mode)
- 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
- Press enter to push quiet splash to the new line, then press CTRL + X to save and reboot
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