Change the Root Password on a Linux Server

Sometimes a root password reset is needed, perhaps a system administrator has left your place of work and not documented the root password, or you have experienced an error in the operating system error that has halted the system in read-only mode.

To change a password on Linux, like a user account, you’d typically use the Operating System through the passwd command (sudo passwd).

Nevertheless, the scenario differs when dealing with the root account, as a significant portion of the file system is mounted via root processes.

The Linux boot process explained

Root is a special user account, and it’s important for system administrators to learn how to reset the root password, it is important to know how a Linux Operating System boots. This tutorial focuses on the GRUB2 bootloader and the startup sequence completed by systemd.

The Linux boot process is quite simple, you power on your PC or Server then:

  • The System loads BIOS or UEFI
    • BIOS – basic input/output system
    • UEFI – unified extensible firmware interface
  • Next Loads GRUB2 (Grand Unified Bootloader version 2)
  • Kernel starts
  • Systemd starts

To change the root password you have to break the boot process at GRUB2 stage.

How to break the Linux boot process

There are 3 ways to break the boot process on Linux. The first 2 ways are manually entered break commands added to the boot.cfg file. The final way is using a boot disk and using rescue mode .

  1. Rd.break – enters emegency mode with no system disk loaded
  2. emergency  – similar to rd.break but mounts system disk
  3. Rescue – like single user mode, disk mounted and services started

To change the root password, you must use rdbreak because this process doesn’t mount the system disk. Mounting a system disk implements file system permissions. Consequently, you cannot change the root password; instead, you’ll be prompted for the root password.

How to change the Linux root password:

Ensure you start with your Linux Server powered off.

  • Power on your server
  • At the GRUB2 boot screen press e to edit  boot.cfg
  • Add the command rd.break after the boot image .img as per the picture above
  • Choose to continue the startup process.
  • the rd.break command will break the boot process and you will get a shell prompt
  • Mount the system root using the command
 mount -o rw,remount /sysroot/ 
  • Access the shell by typing
chroot sysroot

Now type passwd to change root password


Important: now you have changed the root password, you must relabel the filesystem so that the files and folders are aware of the new password hashes. Simply type:

touch ./autorelabel

Now mount disks as read only

mount -o ro,remount /sysroot

Then reboot

Example of the reboot process

Once the server reboots you will be able to log in with your newly changed root password. Its a little daunting when doing this for the first time, but after a while it will become second nature.

What to learn more important Linux Procedures? Check out our popular tech quickies.

Elsewhere On TurboGeek:  Ext4 Data Recovery


Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

6 Responses

  1. 07/11/2022

    […] Part 4 – How to change the root password on Red Hat […]

  2. 20/03/2023

    […] Part 4 – How to change the root password on Red Hat […]

  3. 24/03/2023

    […] Part 4 – How to change the root password on Red Hat […]

  4. 21/08/2023

    […] Part 4 – How to change the root password on Red Hat […]

  5. 21/08/2023

    […] Part 4 – How to change the root password on Red Hat […]

  6. 16/10/2023

    […] Part 4 – How to change the root password on Red Hat […]

Leave a Reply

Your email address will not be published. Required fields are marked *