Who never forgot a root password on a running machine that you can’t reinstall totally?
Most of the linux distributions do have a recovery partition that you can use for that on startup (I won’t detail this here). But if you don’t have this partition, you can still reset it using generic commands thanks to grub capabilities.
Here is the procedure for resetting root password on most of the linux distros using GRUB:
- Reboot the machine
- When you get the GRUB menu, go to edit page by pressing e when highlighting the correct line you want to modify (generally it’s the first one, no need to change)
- Go to the kernel line and enter e again for editing
- Remove the quiet word at the end of the line and replace with that:
- Press enter to validate your changes
- Press b to boot (that way, changes will only be temporary)
- You’re now getting a root bash prompt for your machine
- The root filesystem is mounted as readonly by default, you have to mount it as read/write by typing
mount -n -o remount,rw /
- Use the passwd command to create a new root password (pay attention to keyboard layout that can be different!)
- Reboot and log into your server with your freshly created password
You should now be able to connect perfectly to your server with your new password!