Changing root password Ubuntu
At a glance#
- Purpose: Reset a forgotten root or user password on Ubuntu using GRUB recovery mode.
- Applies to: Ubuntu Server and Desktop 18.04 and later.
- Risk: High — requires a reboot and full downtime.
- Time: About 10 minutes, plus reboot time.
Overview#
If the root password is lost and no account with sudo rights remains, the system has to be booted into recovery mode, where a root shell is available without authentication. The password can then be reset directly.
This needs console access — physical, IPMI/iDRAC, or the VM console. It cannot be done over SSH.
Note: Anyone with console access to an unencrypted Ubuntu machine can do this. Where that is a concern, set a GRUB password and use full-disk encryption.
Before you start#
- Confirm console access and the ability to watch the machine boot.
- Schedule downtime.
- Check whether another account still has
sudo. If one does, usesudo passwd rootand skip this entirely.
Procedure#
1. Reboot and open the GRUB menu#
Reboot, and hold Shift (BIOS systems) or press Esc repeatedly (UEFI systems) as the machine starts.
On a server with a single installed OS, GRUB is often hidden with a zero timeout, so start pressing before you expect to see anything.
2. Select recovery mode#
- Choose Advanced options for Ubuntu.
- Select the entry ending in (recovery mode).
- Wait for the recovery menu to appear.
3. Drop to a root shell#
From the recovery menu, select root — Drop to root shell prompt and press Enter.
Press Enter once more if prompted for maintenance mode.
4. Remount the filesystem as writable#
Recovery mode mounts the root filesystem read-only. Password changes will fail until you remount it:
mount -o remount,rw /Warning: This is the step most often missed. Without it, passwd appears to accept the new password but fails with an authentication token error, and the change is silently lost.
If the system uses a separate /home partition and you need it, mount everything:
mount -a5. Identify the account you need#
List the real user accounts on the machine — system accounts have UIDs below 1000:
awk -F: '$3 >= 1000 && $3 < 65534 {print $1}' /etc/passwdTo see all accounts including system ones:
cut -d: -f1 /etc/passwd6. Reset the password#
For root:
passwd rootFor a specific user:
passwd usernameEnter the new password twice. Nothing is echoed as you type, which is normal.
Note: On Ubuntu the root account is normally locked by design, and administration is done throughsudo. Rather than enabling root, it is usually better to reset the password of an existingsudouser. If you do set a root password here, consider re-locking it afterwards withpasswd -l rootonce you have restoredsudoaccess.
7. Optional — restore sudo access instead#
If the problem is that no account has sudo any more, create one or repair the existing one:
adduser newadmin
usermod -aG sudo newadmin8. Return and reboot#
exitChoose resume — Resume normal boot from the recovery menu, or reboot cleanly:
reboot -fVerification#
Log in at the console with the new password.
Then confirm remote access works before leaving the console:
ssh username@<server-ip>If you reset a sudo account, verify escalation works:
sudo -vTroubleshooting#
| Symptom | Cause and fix |
|---|---|
| GRUB menu never appears | Hold Shift from power-on, or press Esc repeatedly on UEFI. Afterwards, set GRUB_TIMEOUT=5 in /etc/default/grub and run update-grub so it is easier next time. |
passwd: Authentication token manipulation error | Filesystem is still read-only. Run mount -o remount,rw / and try again. |
| Password accepted but login still fails | The change was written before remounting read-write and was lost. Repeat from step 4. |
sudo: command not found in recovery shell | You are already root in recovery mode. Drop sudo from the command. |
No root — Drop to root shell prompt option | Some minimal images omit it. Use the RHEL-style method instead: edit the GRUB entry and append init=/bin/bash. |
| SSH login refused after reset | Root SSH login is disabled by default. This is correct behaviour — log in as a normal user and use sudo. |
Related#
- Changing root password Redhat — the RHEL equivalent, which also requires an SELinux relabel.
- Hardening Linux Server