In the Linux operating system, the root user is a superuser with unrestricted access to all files, commands, and system settings. There are various scenarios where you might need to reset the root password, such as forgetting the current password or rotating credentials after a security incident. This guide covers the fundamental concepts, the most reliable reset methods for different distributions, and the common practices and best practices that let you reset the root password safely.
The root user in Linux is similar to the administrator account in Windows. It has the highest level of privileges and can perform any operation on the system. However, because of this high-level access, it should be used with caution. Day-to-day tasks are usually run from a regular account with sudo used only when administrative privileges are required.
In Linux, user passwords are stored as hashes in the /etc/shadow file, which is readable only by the root user (and on some distributions by members of the shadow group). Each line contains nine colon-separated fields, starting with the login name and the encrypted password, followed by password-aging information such as the date of the last password change and the maximum password age.
The passwd command manages this file for you through the shadow-utils tools and PAM, so you do not need to edit /etc/shadow by hand. When you reset the root password, you are effectively replacing the hash in the corresponding root entry.
Every method below works by interrupting the boot process before the normal login prompt appears. That means anyone with physical or console access to a machine can use them to reset the root password. Protecting the bootloader and encrypting the disk are therefore essential controls, not optional extras.
Most of these methods begin the same way: reboot the machine and interrupt the bootloader.
Opening the GRUB menu: On most Linux distributions GRUB appears for a few seconds at boot. If it is hidden, hold Shift on older BIOS systems or tap Esc repeatedly on UEFI systems while the firmware screen is visible. Once the menu appears, use the arrow keys to highlight an entry, press e to edit it, and press Ctrl + x or F10 to boot the modified entry. Any change made this way is temporary and applies to this boot only.
Method 1: Reset with init=/bin/bash (Debian, Ubuntu, and Most Distributions)#
This is the simplest and most portable method. It tells the kernel to start a shell instead of the normal init system.
Reboot and open the GRUB menu, then highlight the default boot entry and press e.
Locate the kernel line: find the line that begins with linux, linux16, or linuxefi.
Modify the kernel parameters: change ro to rw and append init=/bin/bash at the end of the line. The rw flag mounts the root filesystem read-write, and init=/bin/bash starts a root shell instead of the standard init process.
Boot into the modified environment: press Ctrl + x (or F10).
Confirm write access: if the shell cannot write to disk, remount the root filesystem read-write:
mount -o remount,rw /
Reset the root password: use the passwd command. You will be prompted to enter the new password twice:
passwd root
Relabel SELinux (only if applicable): on Fedora, RHEL, CentOS, Rocky, and AlmaLinux, create the autorelabel trigger so SELinux reloads the changed file:
touch /.autorelabel
Reboot: hand control back to the normal init process:
exec /sbin/init
If that fails, use reboot -f to force a reboot.
Method 2: Reset with rd.break (RHEL, CentOS, Fedora, Rocky, AlmaLinux)#
On systemd and SELinux-based Red Hat family distributions, rd.break is the officially recommended approach because it preserves the correct SELinux context handling.
Reboot and edit the boot entry as described above, then locate the line beginning with linux or linux16.
Modify the kernel parameters: append rd.break at the end of the line. This drops the system into a Dracut emergency shell before the normal root filesystem is mounted. Press Ctrl + x to boot.
Remount the root filesystem read-write:
mount -o remount,rw /sysroot
Chroot into the system:
chroot /sysroot
Reset the root password:
passwd root
Relabel SELinux: tell SELinux to relabel the filesystem on the next boot so it accepts the changed password file:
touch /.autorelabel
Exit and reboot:
exitreboot -f
The relabeling step can take several minutes on large filesystems. After it completes, the system reboots automatically.
Single user mode was the classic reset technique, but it is unreliable on modern systems.
Reboot and edit the boot entry, then locate the kernel line.
Append single or 1 to the end of the line and boot with Ctrl + x.
Reset the password from the shell with passwd root.
On modern systemd distributions this parameter boots the rescue.target, which still starts sulogin and prompts for the root password — so it often cannot help when the password is lost. If it does drop you to a shell, remember that the root filesystem may be mounted read-only, in which case run mount -o remount,rw / before changing the password. When single user mode fails, use Method 1 or Method 2 instead.
Verify the new password: after rebooting, log in or run su - to confirm the reset worked before relying on the system.
Back up important data: before attempting to reset the root password, back up important data on the system. This ensures you do not lose critical information if something goes wrong during the process.
Keep a record of the new password: store the new root password in a secure password manager. Avoid writing it on paper left near the machine or using easily guessable passwords.
Use a live USB as a fallback: if GRUB is locked or the system will not boot, boot from installation media and chroot into the installed system to run passwd.
Use strong passwords: when resetting the root password, use a strong, unique password that includes a combination of uppercase and lowercase letters, numbers, and special characters. A password manager helps generate and recall it.
Limit root access: limit the use of the root account. Use a regular user account for day-to-day tasks and sudo when administrative privileges are required.
Protect the bootloader: password-protect GRUB and set a BIOS/UEFI firmware password so an unauthorized person cannot edit kernel parameters at boot.
Encrypt the disk: full-disk encryption (for example, LUKS on Linux) ensures that even if physical access is obtained, the data cannot be read without the passphrase.
Rotate passwords: periodically update the root password and any credentials you reset after a security incident.
Remove temporary access: after recovery, exit the emergency shell and reboot into the normal system rather than leaving a passwordless root shell running.
Which file stores the root password?
The password hash is stored in /etc/shadow. The passwd command updates it for you; you should not edit the file directly.
What if the GRUB menu is password-protected?
You will need the GRUB password, or you can boot from a live USB and chroot into the installed system to reset the password. This is one reason GRUB protection is a good security control.
What if the disk is encrypted with LUKS?
The reset methods require the root filesystem to be writable, so you must first unlock the encrypted volume with its passphrase. Without the passphrase, the password cannot be reset.
Can I reset the root password without rebooting?
No. Changing another user's password requires root privileges, which is exactly what you are trying to recover. A reboot into an emergency shell is required.
Why is touch /.autorelabel needed?
On SELinux-enabled distributions, changing /etc/shadow outside the running system leaves the file with an incorrect security context. Creating /.autorelabel tells SELinux to relabel the filesystem on the next boot so the change is accepted.
Resetting the root password in Linux is a crucial recovery task that can be accomplished through several methods. Use init=/bin/bash for Debian, Ubuntu, and most distributions, rd.break for the Red Hat family, and Ubuntu's recovery mode when you prefer a menu-driven approach. By understanding the fundamental concepts, following the correct steps for your distribution, and applying the security guidelines above, you can restore access safely and protect the system from unauthorized access.
This guide provides a detailed, distribution-aware approach to resetting the root password in Linux. By following the steps and best practices outlined here, you can successfully reset the root password and maintain the security of your Linux system.