How to Reset the Root Password on Linux: Ubuntu, Debian, AlmaLinux

A forgotten root password does not mean a lost server. If you can reach the console — physical, or VNC in your hosting control panel — you can set a new password in a few minutes. The method depends on the distribution and on what access you still have.
Check the easy options first
You have a user with sudo rights. No reboot needed:
sudo passwd root
You log in with an SSH key. If key-based root login works, run passwd — it will not ask for the old password.
Hosting control panel. Many providers offer a password reset right in the server control panel. Check this before rebooting.
If none of these apply, you need the server console. On a VPS that is the VNC console in the control panel: SSH will not do, because you have to interrupt the boot process.
Ubuntu and Debian: reset through GRUB
- Reboot the server and wait for the GRUB menu. If it does not appear, hold
Shiftright after boot starts (BIOS systems) or tapEsca few times (UEFI systems). - Select the main entry and press
eto edit the boot parameters. - Find the line that starts with
linux. At its end, replacerowithrwand addinit=/bin/bash:
linux /boot/vmlinuz-... root=UUID=... rw init=/bin/bash
- Press
Ctrl+XorF10. The system boots straight into a root shell without asking for a password. - Set a new password:
passwd
- Flush the changes to disk and reboot:
sync
reboot -f
The edited boot parameters apply once: on the next reboot the system starts normally.
AlmaLinux, Rocky Linux, RHEL: rd.break
On these systems you also have to deal with SELinux.
- Reboot the server, select the main entry in the GRUB menu and press
e. - Find the line starting with
linuxand appendrd.break. - Press
Ctrl+X. Boot stops early at theswitch_root:/#prompt. - Remount the system partition read-write and switch into it:
mount -o remount,rw /sysroot
chroot /sysroot
- Set a new password:
passwd
- Create the file that tells SELinux to relabel the filesystem on boot. Without this step you will not be able to log in:
touch /.autorelabel
- Leave the shell and continue booting:
exit
exit
Relabelling takes from a couple of minutes to half an hour depending on disk size. The server reboots by itself — do not interrupt it.
If rd.break asks for the root password, use init=/bin/bash instead, as in the Ubuntu instructions, and also run touch /.autorelabel after changing the password.
Works on any distribution: rescue mode
If the boot loader is password-protected or you cannot edit its parameters, boot the server from a live image or in the rescue mode many providers offer in their control panel.
- Identify the root partition of the installed system:
lsblk -f
- Mount it and switch into the installed system:
mount /dev/sda2 /mnt
chroot /mnt
- Change the password and leave:
passwd
exit
umount /mnt
On systems with SELinux, run touch /.autorelabel before exiting. Then boot the server from its main disk.
If the disk is encrypted (LUKS), open it first with cryptsetup open — you will need the encryption passphrase. Without it the data cannot be recovered.
After you are back in
- Confirm the login works before closing the console.
- Set up SSH key login so the root password is only needed at the console; add two-factor SSH authentication for critical servers.
- Create a separate sudo user. Next time you can change the root password without rebooting.
- Store the password in a password manager — for example your own Vaultwarden.
Why this is possible at all
Anyone with console access to a server can get root — that is a property of every system, not a Linux vulnerability. Protect access to your hosting control panel at least as well as the server itself: with a strong password and two-factor authentication.


