How to Recover the Root Password on Linux
If you forgot the root password of your dedicated server, set a new one from rescue mode. You start the rescue system, open the disk of your installed Linux and change the password there. The steps were tested on Ubuntu 26.04 LTS with the GRML rescue image; they work the same on other Linux systems.
On a VPS, reset the password in the Client Area instead: How to Find and Reset the Root Password for a VPS.
1. Start Rescue Mode and Log In
Start rescue mode in the Client Area and log in as root with the rescue password from the Credentials tab: How to Use Rescue Mode.
2. Set the New Password
List the disks and find the partition of your installed system (1). It is usually the largest ext4 or xfs partition of the first disk; here it is sda5:
lsblk -o NAME,SIZE,TYPE,FSTYPE
Mount it (2), then run passwd inside your installed system (3):
mount /dev/sda5 /mnt chroot /mnt passwd root
Type the new password twice. Nothing appears while you type. The answer is password updated successfully.
Software RAID
If you installed the server with software RAID, the rescue system does not start the RAID arrays by itself. Start them and mount the array that holds /:
mdadm --assemble --scan lsblk -o NAME,SIZE,TYPE,FSTYPE mount /dev/md125 /mnt chroot /mnt passwd root
In the rescue system the arrays may have other numbers than in your installed system. For example, on a server with RAID 1 on two disks, / is the 3.6 TB array md5 in Ubuntu and md125 in GRML; the small arrays are /boot, /tmp and swap. Take the largest ext4 or xfs array.
If you open a shell in your installed system with chroot /mnt alone, GRML tries to start its own shell zsh, which Ubuntu and Debian do not have: chroot: failed to run command '/bin/zsh': No such file or directory. Add /bin/bash at the end:
chroot /mnt /bin/bash passwd root exit
3. Restart the Server
umount /mnt reboot
The server starts its installed system again. It answers SSH after about 3 minutes. Log in as root with the new password: How to Connect to a Linux Server via SSH.
If the New Password Is Refused
If you switched password login off (Log In to Your Linux Server With an SSH Key), SSH refuses every password, also the new one. Add your public key instead, in step 2 after the mount line:
mkdir -p /mnt/root/.ssh echo "ssh-ed25519 AAAA... you@computer" >> /mnt/root/.ssh/authorized_keys chmod 700 /mnt/root/.ssh chmod 600 /mnt/root/.ssh/authorized_keys
Replace the text in quotes with the content of your id_ed25519.pub. After the restart you log in with your key.
If /mnt/etc/passwd does not exist after mounting, you mounted another partition (for example /boot). Unmount it with umount /mnt and try the next one.
