When this guide applies
This guide is for administrators who own or are authorised to manage a Debian 12, AlmaLinux 9 or Rocky Linux 9 server and have lost the root password. It covers the two situations people meet most often: the machine still reaches the GRUB menu, and the machine needs a provider rescue console or live media. It does not cover password cracking, account takeover, or work on machines you do not own.
If you can still log in with another administrator account, use sudo passwd root or sudo passwd username instead. The recovery methods below are for a locked root account. Before you start, take a snapshot or confirm you have a recent backup. A root password change is small, but a failed boot or a damaged /etc/shadow is not.
Prerequisites
- Console access: physical keyboard and screen, a provider VNC or serial console, or a working rescue environment.
- A snapshot, backup, or at least a known-good copy of
/etc/passwdand/etc/shadowstored securely. - Knowledge of whether the root filesystem is plain, LVM, encrypted with LUKS, or part of a RAID array.
- For AlmaLinux 9 and Rocky Linux 9, an understanding that SELinux may need to relabel files after a password change.
- A provider rescue console or live media if GRUB itself will not load. On a Tarisu VPS or dedicated server, the rescue mode and console access in the control panel are the relevant path.
Keep the new root password private. A root password reset is not an incident-response procedure. If you suspect the machine has been compromised, isolate it, preserve evidence, and rebuild rather than treating a password change as a fix.
Back up before you touch the boot line
If the system is still up, make a provider snapshot. If it will not boot, do not improvise with a live USB until you have checked whether the provider offers a rescue environment. A snapshot taken before the change gives you a clean rollback point if GRUB editing or SELinux relabelling goes wrong.
If you must copy files manually, store them on encrypted removable media or a secured location. Do not leave a copy of /etc/shadow on an unencrypted USB stick or a public share. The shadow file contains password hashes and is sensitive.
Method 1: Debian 12 through GRUB and init=/bin/bash
This is the quickest method when GRUB is intact and the root filesystem is not encrypted. Debian 12 uses GRUB with a kernel command line that you can edit at boot time. You will append one option, boot into a root shell, remount the root filesystem read-write, change the password, and hand control back to systemd.
- Reboot the Debian 12 machine. At the GRUB menu, select the normal Debian entry but do not press Enter. Press
eto edit it. - Find the line that starts with
linux. Move the cursor to the end of that line and append the following option exactly, with a space before it:
init=/bin/bash
Do not remove the existing root= or ro options. If the line is long, it may wrap on screen, but it is still one line. Press Ctrl+X or F10 to boot.
- Wait for the kernel to hand over to a bash prompt. Check where the root filesystem is mounted:
findmnt /
If the target shows ro, remount it read-write:
mount -o remount,rw /
- Set the root password. You will be asked twice, and the screen will not echo the characters:
passwd root
A successful change ends with a message such as password updated successfully. If you see Authentication token manipulation error, stop and check the filesystem state in the troubleshooting section below.
- Sync the filesystem and re-exec the normal init system:
sync
exec /sbin/init
The machine should continue booting into the normal login prompt. If it does not, use the provider console or a rescue environment rather than repeatedly editing GRUB.
What you should see on Debian 12
After the password change, the system boots normally. Log in as root once to confirm the new password works, then log out. Run passwd -S root as root to confirm the account status shows a usable password. Check last and journalctl -b if you want to review the reboot and login. Do not leave an extra root shell open on the console after testing.
Method 2: AlmaLinux 9 and Rocky Linux 9 with rd.break
AlmaLinux 9 and Rocky Linux 9 are RHEL-family systems. They use SELinux by default, so the safest recovery path is rd.break rather than a bare init=/bin/bash. The rd.break option drops you into an emergency shell before the real root is switched in. The real root is then mounted at /sysroot. After changing the password, create /.autorelabel so SELinux relabels the new shadow file on the next boot.
- Reboot and wait for the GRUB menu. Select the current kernel entry and press
e. - Find the
linuxline and append the following at the end:
rd.break enforcing=0
Press Ctrl+X or F10. You should reach a prompt similar to switch_root:/#.
- Remount the real root filesystem read-write:
mount -o remount,rw /sysroot
- Enter the real root with chroot:
chroot /sysroot
- Change the root password:
passwd root
- Tell SELinux to relabel the filesystem on the next boot. Run this from inside the chroot:
touch /.autorelabel
- Sync, leave the chroot, remount the real root read-only, and reboot:
sync
exit
mount -o remount,ro /sysroot
reboot
If the rescue shell does not provide a working reboot command, use the provider console or a clean power reset only after the password has been set and the filesystem has been synced. Do not pull the plug while the relabel flag is being written.
What you should see on AlmaLinux 9 and Rocky Linux 9
The first boot after the change may take longer while SELinux relabels files. Wait for the login prompt. Log in once as root, then check getenforce. It should report Enforcing after a normal reboot. The enforcing=0 option applies only to that boot; if it still shows Permissive, edit the GRUB line again and remove enforcing=0. Run sestatus if you need more detail. Confirm the password with passwd -S root.
Method 3: provider rescue console or live media
Use this method if GRUB will not load, the kernel command line cannot be edited, the root filesystem is encrypted and you have the passphrase, or the system drops to a dracut emergency shell. On a Tarisu VPS or dedicated server, use the provider rescue mode and console access rather than guessing at disk layout. On your own hardware, use a trusted live image.
- Boot the rescue environment and identify the root disk and partitions:
lsblk
fdisk -l
For LVM, activate the volume group and list the logical volumes:
vgchange -ay
lvs
Use the device names shown by those commands. The example below assumes the root filesystem is /dev/sda3; replace it with the real partition or logical volume.
- Mount the real root filesystem under
/mnt:
mount /dev/sda3 /mnt
If the system uses separate /boot or /usr partitions, mount those under /mnt as well. Do not skip this if the layout requires it.
- For AlmaLinux 9 or Rocky Linux 9, create the SELinux relabel flag on the real root before chroot:
touch /mnt/.autorelabel
- Bind the virtual filesystems so the chroot can run normally:
for d in dev proc sys run; do mount --bind /$d /mnt/$d; done
- Enter the installed system and change the password:
chroot /mnt /bin/bash
passwd root
- Leave the chroot, unmount everything, and reboot:
exit
umount -R /mnt
reboot
If umount -R reports that a target is busy, check that you have left the chroot and that no shell is holding the mount. Do not force unmounting blindly on a filesystem that may still be writing.
What you should see with rescue media
After the reboot, the normal boot process should continue and the login prompt should accept the new root password. On AlmaLinux 9 and Rocky Linux 9, allow the SELinux relabel to finish. Then verify getenforce and passwd -S root. If the system boots but the password is rejected, the most common causes are a mistaken partition mount, a chroot that ran against the wrong filesystem, or a damaged /etc/shadow.
Troubleshooting common errors
The GRUB menu does not appear
On BIOS systems, hold Shift while the firmware hands off. On UEFI systems, press Esc repeatedly. If the provider console shows a blank screen or a firmware error, use the provider rescue environment. If GRUB is hidden by configuration, that is a separate fix that requires access to the installed system first.
Debian drops to a kernel panic after init=/bin/bash
A panic with a message about no init found usually means the kernel command line is malformed, the initramfs is missing, or the root= value is wrong. Use an older kernel entry if one exists, or use rescue media. Do not keep editing the same line without checking the exact boot entry.
passwd reports an authentication token manipulation error
Check that the root filesystem is read-write and that /etc/shadow exists and is readable:
findmnt /
df -h
mount -o remount,rw /
ls -l /etc/shadow
If the filesystem is full, free space or restore a backup. If /etc/shadow is missing or corrupted, restore it from a secure backup. Do not create a new empty shadow file and hope for the best.
AlmaLinux or Rocky Linux drops to a dracut emergency shell
If rd.break does not reach the expected prompt, the initramfs may not be able to find the root device. Check the disk with lsblk, activate LVM with vgchange -ay if needed, and mount the correct root at /sysroot. If the root is encrypted, enter the LUKS passphrase when prompted. Without that passphrase, the password cannot be recovered this way.
SELinux relabelling takes a long time or boot fails
Wait for the relabel to finish on the first boot. If the system will not boot, use rescue media and check that /.autorelabel was created on the real root, not only inside a temporary chroot. If you booted with enforcing=0, remove it from the GRUB line after the system is stable and verify getenforce returns Enforcing. Do not disable SELinux permanently as a convenience.
The root password works at the console but not over SSH
That is an SSH policy issue, not a password recovery failure. Check the SSH daemon configuration for PermitRootLogin. On a production server, use a normal user with sudo instead of enabling direct root login. Restart the SSH service only after testing the configuration.
The root filesystem is on an encrypted volume
GRUB editing can still work if the firmware and bootloader can prompt for the LUKS passphrase. If you do not have the passphrase, a password reset is not possible without data loss. Restore from backup or rebuild the machine.
Security notes
- Anyone with console or rescue access can change the root password. Protect provider accounts, VNC sessions, and physical access with the same care as root credentials.
- Choose a long, unique root password and store it in a password manager. Do not reuse a password from another service.
- Prefer a normal administrator account with sudo for daily work. Root should be reserved for tasks that genuinely require it.
- After recovery, review recent authentication and boot records with
last,journalctl -b -1, and the system authentication logs. If you see signs of unauthorised access, rebuild the server. - On AlmaLinux 9 and Rocky Linux 9, keep SELinux enforcing. The
.autorelabelflag is a one-time recovery step, not a permanent configuration. - Take a snapshot before the change and keep it until the system has booted and accepted the new password. This is the simplest rollback path.
FAQ
Can I use these exact steps on Ubuntu?
Not always. Ubuntu and Debian share some tooling, but Ubuntu releases often use different recovery defaults and package layouts. This guide is written for Debian 12, AlmaLinux 9 and Rocky Linux 9. Use the distribution-specific procedure for other releases.
Do I need the old root password to edit GRUB?
No. GRUB editing happens before the installed system asks for a password. On Debian, the recovery mode may ask for the root password, but the init=/bin/bash method does not. On AlmaLinux and Rocky Linux, rd.break does not require the old root password.
Will resetting the root password also unlock a normal user account?
No. A normal user account is changed separately with passwd username from an administrator session. Root recovery does not change user passwords, SSH keys, or application accounts.
Is init=/bin/bash safe on AlmaLinux or Rocky Linux?
It can work, but rd.break is the safer default for RHEL-family systems because it makes the chroot step explicit and pairs naturally with SELinux relabelling. If you use init=/bin/bash there, you still need to remount the real root read-write and create /.autorelabel before rebooting.
What if the machine is a cloud VPS?
Use the provider console or rescue mode. The same GRUB and chroot logic applies, but the disk names and boot environment depend on the provider. On a Tarisu VPS or dedicated server, use the rescue environment described in the control panel and keep the new root password private.
Does a password reset fix a corrupted shadow file?
No. If /etc/shadow is damaged, restore it from a secure backup before changing anything else. A reset that writes into a corrupted file can make the situation harder to diagnose.