Skip to content

Expert · Boot, recovery and containers · topic 41 of 57 · 30 min

Recovering a lost root password

Explanation

If nobody knows the root password, you can reset it from the console: interrupt the boot with rd.break (or init=/bin/bash), remount the real root read-write, chroot into it, run passwd, and touch /.autorelabel so SELinux fixes the labels on the next boot. It needs console access, which is why physical and console security matter.

When you need this

An admin leaves without handing over passwords, or a lab VM's root password is forgotten. If no one with sudo can log in, the only way back is to stop the boot before normal logins and change the password directly. You need access to the console: the physical screen and keyboard, or the virtual console of a VM or cloud instance.

Careful: Do this only on systems you are responsible for and allowed to change. On company servers, follow the change process and inform security; the reset is visible in the logs and the audit trail.

Method 1: rd.break (the classic RHCSA method)

rd.break tells the initramfs to stop just before it switches to the real root, and give you a shell. At that moment the real root file system is mounted read-only at /sysroot, and SELinux is not yet active.

bash
# 1. Reboot. In the GRUB menu, select the normal entry and press e.
# 2. Go to the end of the line starting with "linux" and add:  rd.break
#    (on some VMs and cloud images you must also remove console=ttyS0 arguments
#     to see the shell on your screen)
# 3. Press Ctrl+X. You get a prompt:
switch_root:/# mount -o remount,rw /sysroot
switch_root:/# chroot /sysroot
sh-5.1# passwd root
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
sh-5.1# touch /.autorelabel
sh-5.1# exit
switch_root:/# exit
The second exit continues the boot. The relabel runs, the system reboots once more, and then you can log in with the new password.

Why touch /.autorelabel?

passwd writes a new /etc/shadow file. Because SELinux was not running, the new file is created without the correct label (shadow_t). On the next boot, an enforcing system would block programs from reading it, and nobody could log in. The empty file /.autorelabel tells the boot to relabel the whole file system. This can take several minutes on large disks; let it finish.

Method 2: init=/bin/bash

This method replaces systemd with a bash shell for one boot. It works on any distribution and is handy when rd.break does not behave on a particular system.

bash
# In GRUB, press e, and at the end of the "linux" line add:  init=/bin/bash
# Press Ctrl+X. You get a root shell on the REAL root, mounted read-only:
bash-5.1# mount -o remount,rw /
bash-5.1# passwd root
bash-5.1# touch /.autorelabel
bash-5.1# exec /sbin/init          # continue a normal boot (or: /usr/sbin/reboot -f)
rd.breakinit=/bin/bash
Where you stopInside the initramfs, before switch-rootOn the real root, instead of systemd
Real root mounted at/sysroot (read-only)/ (read-only)
Needs chrootYes: chroot /sysrootNo
SELinux relabeltouch /.autorelabeltouch /.autorelabel

Protecting against this

The same trick lets anyone with console access become root. Defences: a GRUB password (grub2-setpassword), a firmware password and disabled USB boot, locked server rooms, restricted access to VM consoles in vCenter or the cloud portal, and full-disk encryption (LUKS) so the disk cannot be read without its passphrase.

Common mistakes

  • Forgetting touch /.autorelabel: the password is changed, but logins fail after reboot with SELinux enforcing.
  • Forgetting to remount read-write: passwd fails with "Authentication token manipulation error".
  • With rd.break, running passwd before chroot /sysroot: you change the password inside the temporary initramfs, which is thrown away.
  • Interrupting the relabel because it "looks stuck". Wait.
Tip: In the exam, practise this until you can do it without notes in under five minutes. Check the current exam objectives; resetting the root password has long been a core RHCSA skill.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Recovering a lost root password · 1/7

Console access needed

If no one knows the root password, you can reset it from the console.

Prefer a video by a teacher? Find free videos on “rhel 9 reset root password rd.break autorelabel” on YouTube ↗

In real life: A college lab after the old admin left

A college computer centre in Bhopal inherited RHEL lab servers from an admin who had left, and no one knew the root password. With the principal's written approval, the new admin reset the password on each server from the console with rd.break, recorded the change in the lab register, and then created named sudo accounts for the two lab assistants so a shared root password would not be needed again.

bash
switch_root:/# mount -o remount,rw /sysroot
switch_root:/# chroot /sysroot
sh-5.1# passwd root
sh-5.1# touch /.autorelabel
sh-5.1# exit
switch_root:/# exit

Practice (0/3 done)

Task 1 · Question

After rd.break, where is the real root file system mounted?

Task 2 · Question

Which line has the bug? (rd.break method) 1: mount -o remount,rw /sysroot 2: passwd root 3: chroot /sysroot 4: touch /.autorelabel

Task 3 · Practice

Take a snapshot of your lab VM, then reset its root password with rd.break. Afterwards reset it again using init=/bin/bash. Time yourself.

Quick quiz

Question 1

1.Why must you run touch /.autorelabel after resetting the password this way?

Question 2

2.Which kernel argument replaces systemd with a bash shell for one boot?

Question 3

3.passwd says "Authentication token manipulation error". Likely cause?

Question 4

4.What best protects a server from this reset by someone at the console?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Why must you run touch /.autorelabel after resetting the password this way?

Answer: The new /etc/shadow has no correct SELinux label; the relabel fixes it

SELinux was not running when the file was written.

Which kernel argument replaces systemd with a bash shell for one boot?

Answer: init=/bin/bash

init= sets the first program the kernel runs.

passwd says "Authentication token manipulation error". Likely cause?

Answer: The file system is still read-only

Remount read-write first.

What best protects a server from this reset by someone at the console?

Answer: A GRUB password plus physical/console access control (and disk encryption)

The reset bypasses the root password entirely.

What does SELinux add to normal Linux permissions?Related

Answer: Mandatory, label-based rules that even root processes must follow

It is mandatory access control based on labels.

From SELinux: what it is and its modes

Which file shows the kernel arguments of the current boot?Related

Answer: /proc/cmdline

/proc/cmdline.

From The boot process, step by step

Where are RHEL 9 per-kernel boot entries stored?Related

Answer: /boot/loader/entries/

BLS entries live in /boot/loader/entries/.

From GRUB2, kernel arguments and the default kernel

Which file can only root read?Related

Answer: /etc/shadow

/etc/shadow holds the password hashes, so it is readable by root only.

From Users, groups and the files behind them

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 2 more topics in “Boot, recovery and containers” before its exam: Containers with Podman: images, run, ports and logs, Persistent storage and containers as systemd services.
  2. Module 8 exam: Boot, recovery and containers · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Ansible fundamentals. 57 topics left in the course before the final exam.

← Previous: GRUB2, kernel arguments and the default kernel