Losing the root password on an Ubuntu machine is annoying, but it is rarely fatal. If you have physical or console access to the machine and it is yours to administer, you can usually regain access in a few minutes without reinstalling anything. This guide covers Ubuntu 22.04 LTS and 24.04 LTS, with short notes for Debian 12 and AlmaLinux 9.
It is written for system administrators, developers and VPS owners who need to get back into their own server or workstation. It is not a way into someone else's system. If you do not own the machine or have written permission to administer it, stop here.
Who this guide is for
Ubuntu locks the root account by default. Most day-to-day administration happens through a user in the sudo group. That distinction matters: a forgotten sudo password is not the same as a forgotten root password. If you can still run commands with sudo, resetting root is a one-line job. If you cannot log in at all, you need console access and one of the recovery methods below.
This guide applies to Ubuntu servers, virtual machines, cloud instances and desktop installations that you control. It also applies to VPS and dedicated servers where the provider gives you a web console or rescue console. It does not apply to shared web hosting, where root access is not part of the service.
Before you start: prerequisites and safety
- Back up first. Take a snapshot if your provider offers one, or copy important data elsewhere. Password recovery should be safe, but a wrong partition or a mistyped command can still cause damage.
- Have console access. You need a keyboard and monitor, a virtual machine console, or the web console for your VPS or dedicated server. SSH alone is not enough if you cannot log in.
- Have an Ubuntu live USB ready for the live-media method. Use the same or a newer Ubuntu release than the installed system.
- Know whether the disk is encrypted. If the root filesystem uses LUKS, you will need the LUKS passphrase. Without it, you cannot reset the password.
- Understand the security boundary. Anyone with physical or console access can usually take over a Linux machine. That is why server rooms, hypervisor consoles and provider panels must be protected.
If your Ubuntu system runs on a Tarisu VPS or dedicated server, use the console provided in your control panel rather than guessing at a physical keyboard. Take a snapshot first where your service includes that option.
First, try the simplest route: you still have sudo
If you can log in as a sudo-capable user, you do not need recovery mode. Set a new root password directly:
sudo passwd root
You will be asked for your own sudo password, then for the new root password twice. A successful reset ends with:
passwd: password updated successfully
You can check the account state with:
sudo passwd -S root
The output starts with root followed by a status field. P means a usable password is set. L means the account is locked. On a default Ubuntu installation, root is normally locked and you use sudo instead. If you only need root for occasional tasks, consider leaving it locked after you finish.
If you forgot your own sudo password but another sudo user can still log in, reset your account from that other account:
sudo passwd yourusername
Method 1: Reset root password from Ubuntu recovery mode
Recovery mode is the least disruptive method when the GRUB menu is available. It boots a minimal environment and gives you a root shell without asking for the password you have forgotten.
Step 1: Open the GRUB menu
Reboot the machine. On a physical BIOS system, hold Shift during boot. On most UEFI systems, press Esc repeatedly as the machine starts. On a virtual machine or VPS console, press the same keys as soon as the console becomes active.
At the GRUB menu, choose Advanced options for Ubuntu, then choose the entry that ends with recovery mode.
Step 2: Drop to a root shell
In the recovery menu, select root — Drop to a root shell prompt. You should see a prompt ending in #. If the system asks for the root password here, use Method 2 instead.
Step 3: Remount the filesystem and set the password
Recovery mode often mounts the root filesystem read-only. Remount it read-write before changing the password:
mount -o remount,rw /
passwd root
Enter the new password twice. You should see passwd: password updated successfully. If you see an authentication token error instead, see the troubleshooting section below.
Step 4: Reboot and verify
Leave the shell and return to the recovery menu:
exit
Choose resume to continue a normal boot, or run reboot -f from the root shell. After the system starts, log in as your normal sudo user and test root access with:
su -
Enter the new root password. If you reach a root prompt, the reset worked.
Method 2: Use GRUB's init=/bin/bash when recovery mode is missing
Some installations do not show a recovery entry, or the recovery shell asks for the password you do not have. In that case, edit the kernel command line for one boot. This change is temporary and is not written to the GRUB configuration.
- Reboot and open the GRUB menu as described above.
- Highlight the normal Ubuntu entry and press
eto edit it. - Find the line that starts with
linux. It usually containsro quiet splash. - Change
rotorw, then addinit=/bin/bashat the end of that line. - Press
Ctrl+XorF10to boot.
The system should boot to a root shell with a prompt like root@hostname:/#. Now run:
mount -o remount,rw /
passwd root
sync
reboot -f
If passwd reports that the authentication token could not be manipulated, the filesystem is probably still read-only. Run the remount command again and check for errors. When the password has been changed, the sync command flushes writes to disk before the forced reboot.
Method 3: Reset from an Ubuntu live USB
If GRUB is inaccessible, or the machine will not boot far enough to edit it, use an Ubuntu live USB. This method also works on many cloud instances if you can attach an ISO through the provider console.
Step 1: Boot the live environment
Write the Ubuntu ISO to a USB stick, boot from it, and choose Try Ubuntu. Open a terminal.
Step 2: Identify the installed root partition
lsblk -f
Look for the partition that holds your installed system. It is often something like /dev/nvme0n1p2 or /dev/sda2. The filesystem type may be ext4, xfs or LVM. Do not mount the USB stick itself.
Step 3: Mount the installed system and chroot into it
Replace the example partition with your own:
sudo mount /dev/nvme0n1p2 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
If your root filesystem is on LVM, activate the volume group first:
sudo vgscan
sudo vgchange -ay
lsblk
Then mount the mapper device, for example /dev/mapper/ubuntu--vg-ubuntu--lv, instead of a plain partition.
Step 4: Set the password and clean up
Inside the chroot, run:
passwd root
You should see the usual password prompts and a success message. Leave the chroot and unmount everything before rebooting:
exit
sudo umount -R /mnt
sudo reboot
Remove the live USB when the machine restarts.
If the disk is encrypted
A LUKS-encrypted Ubuntu installation needs the disk passphrase before you can reach /etc/shadow. From a live USB, open the encrypted container first:
sudo cryptsetup luksOpen /dev/nvme0n1p3 cryptroot
sudo vgscan
sudo vgchange -ay
lsblk
Then mount the decrypted root device, which may be /dev/mapper/cryptroot or an LVM logical volume inside it, and continue with the chroot steps. If you do not know the LUKS passphrase, there is no supported way to reset the root password. Restoring from backup is the practical option.
Debian 12 and AlmaLinux 9: quick differences
Debian 12 behaves much like Ubuntu for this task. Use the recovery entry if it appears, or edit GRUB and boot with rw init=/bin/bash. Then run mount -o remount,rw / if needed, followed by passwd root and a reboot.
AlmaLinux 9 and other RHEL-family systems use a different early-boot break. At the GRUB menu, press e, find the line starting with linux, and append rd.break. Boot with Ctrl+X. At the switch-root prompt, run:
mount -o remount,rw /sysroot
chroot /sysroot
passwd root
touch /.autorelabel
exit
exit
The touch /.autorelabel step is important when SELinux is enforcing. The next boot may take longer while filesystem labels are corrected. Do not skip it unless you have disabled SELinux deliberately.
Troubleshooting common errors
| Problem | Likely cause and fix |
|---|---|
Authentication token manipulation error | The root filesystem is still read-only, the disk is full, or /etc/shadow has an immutable attribute. Run mount -o remount,rw /, check df -h, and inspect with lsattr /etc/shadow. Only remove an immutable flag if you know why it was set. |
| GRUB menu does not appear | Try Esc repeatedly on UEFI systems or hold Shift on BIOS systems. On a VPS, use the provider console and send the key as soon as the boot starts. If GRUB is hidden entirely, use the live USB method. |
passwd: user 'root' does not exist | This is unusual. Check the account entry with grep '^root:' /etc/passwd. If it is missing, restore /etc/passwd and /etc/shadow from backup rather than recreating the account by hand. |
| Root password works at the console but SSH still refuses root | Ubuntu disables direct root SSH login by default. Check the effective setting with sudo sshd -T | grep permitrootlogin. Keep root SSH disabled and use a sudo user with key-based authentication. |
init=/bin/bash does not reach a shell | Check for a typo and confirm that the kernel line contains rw. If the system still fails, boot the live USB and use the chroot method instead. |
| Cloud console has no recovery option | Use the provider's rescue console, attach a live ISO, or boot a rescue profile. Take a snapshot first. The exact menu depends on the provider and the instance type. |
Security notes after a root password reset
- Use a strong, unique password. Store it in a password manager. Do not reuse the password from another server or service.
- Keep root SSH login disabled. Log in as a sudo user and elevate only when needed. A root password reset does not automatically enable remote root login, and it should not.
- Lock root again if your policy requires it. On Ubuntu, you can run
sudo passwd -l rootto lock the root password after you have recovered access. Make sure you still have a working sudo user first. - Protect console access. A provider panel, hypervisor console or physical keyboard is a high-value entry point. Use strong panel credentials, multi-factor authentication where available, and restricted network access.
- Encrypt disks on portable and sensitive systems. Encryption does not stop an authorized recovery, but it protects data if the disk is lost or stolen.
- Review access after the incident. Check recent logins with
lastandwho, and confirm that no unexpected sudo users were added.
FAQ
Can I reset the root password without console access?
Only if you can still use sudo from a logged-in account. In that case, run sudo passwd root. If you cannot log in and have no console, there is no remote recovery path that does not depend on another working account or provider rescue feature.
Does Ubuntu have a root password by default?
No. Ubuntu locks the root account by default and expects administrators to use sudo. Setting a root password is optional. Many administrators leave root locked and rely on sudo users instead.
Does this work on Ubuntu 24.04?
Yes. Ubuntu 22.04 and 24.04 both provide recovery mode and accept the rw init=/bin/bash kernel parameter. The live USB chroot method also works on both releases.
Will resetting the root password let me log in over SSH as root?
Not necessarily. SSH access depends on the PermitRootLogin setting in sshd_config. Ubuntu's default configuration does not allow direct root SSH login. Use a sudo user instead of enabling root SSH.
Can I use this on a Tarisu VPS or dedicated server?
Use the console in your Tarisu control panel for the recovery steps. Take a snapshot or backup first if your service includes that feature. If the console cannot reach GRUB, ask support about rescue or ISO boot options for your specific service.
What if the root filesystem is encrypted and I do not know the passphrase?
You cannot reset the root password without unlocking the disk. Restore the system from backup, or rebuild it if no backup exists. Keep the LUKS passphrase in a secure password manager so this situation does not happen again.