Here is how to reset the root password on Ubuntu when you are locked out and SSH is not an option. This happens more often than people admit: a password manager mix-up, a handover from a previous admin, or simply forgetting a password you set once and never used again. The fix does not need a reinstall. It needs about five minutes with the console.
What you need
- A Hostner dedicated server running Ubuntu
- Access to your Hostner KVM/IPMI console (this only works through the console, not SSH)
- A few minutes where the server can reboot
Step 1: Open the console and reboot
Log into your Hostner dashboard and open the KVM/IPMI console for your server. With the console window open, trigger a reboot from the dashboard’s power controls. Watch the console closely. The GRUB boot menu only shows for a few seconds before it boots automatically.
Alternative: Ubuntu’s recovery mode
Ubuntu ships with something Debian does not have by default: a curated recovery menu. Instead of manually editing the boot line, you can use the arrow keys on the GRUB menu to select “Advanced options for Ubuntu”, then choose the entry marked “(recovery mode)”. From the recovery menu that follows, select “root: Drop to root shell prompt”. This lands you in the same kind of root shell as the manual method, without needing to type init=/bin/bash yourself. Once there, continue from Step 3 below. Both routes end at the same place, so use whichever one you find on your screen.
Step 2: Edit the boot line in GRUB (manual method)
When the GRUB menu appears, use the arrow keys to highlight your Ubuntu boot entry (do not press Enter yet). Press e to edit it. You will see a block of boot parameters. Find the line starting with linux. At the end of that line, change ro to rw, then add:
~ $ init=/bin/bash
Press Ctrl+X or F10 to boot with these changes.
Step 3: Reset the root password on Ubuntu
You should now land in a root shell, no password asked. First, remount the filesystem as writable:
~ $ mount -o remount,rw /
Then set a new password:
~ $ passwd root
Type the new password twice when asked.
Step 4: Reboot normally
Bring the system back to a normal boot:
~ $ exec /sbin/init
Or, if that hangs, force a reboot from your Hostner dashboard instead. Log in with the new password once the server is back up.
If it does not work
If the GRUB menu does not appear at all, you likely missed the short window before autoboot. Reboot again and press a key (any key) the moment the console shows POST output, then try again. If recovery mode drops you into a menu without a clear “root shell” option, check further down the list, some Ubuntu versions bury it under a slightly different label like “root Drop to root shell prompt” or similar wording depending on the release. For background on what each boot parameter does, the Ubuntu GRUB documentation covers it in more detail than we need here.
No ticket for this one. Five minutes in the console and you are back in as root, on your own terms.
Prevent this next time
Once you are back in, consider switching to SSH key authentication instead of a password for root logins. A lost key is easy to replace by adding a new one through the console, the same way you just recovered access, without ever touching a password again.
Also available for: Debian, AlmaLinux. See all guides in Docs.