$ run as a normal user# run as root (or with sudo)
The quick answer
- Reboot, press
eat the GRUB menu, addrd.breakto the end of the line that starts withlinux, press Ctrl+X. - At the
switch_root:/#prompt:
The server boots, relabels SELinux (some minutes, one extra reboot), and the new password works.
Step by step
- Open the console — this does not work over SSH. VMware/Proxmox console, cloud serial console (AWS EC2 Serial Console, Azure Serial Console), or the server's remote management card.
- Stop at GRUB: reboot; when the menu shows, select the normal kernel and press
e. If the menu is hidden, pressEscorShiftduring boot. - **Add
rd.break** at the end of thelinux …line (use the arrow keys,End). Removerhgb quiettoo, so you see messages. Press Ctrl+X to boot. - The emergency shell (
switch_root:/#) runs from the initramfs; the real system is mounted read-only at/sysroot. Make it writable and enter it (quick answer). - Set the password with
passwd root. If you seeAuthentication token manipulation error, the remount did not work — checkmount | grep sysroot. - **
touch /.autorelabel— never skip it.**passwdwrote a new/etc/shadowwithout its SELinux label; without the relabel nobody can log in after the reboot. - Leave with
exittwice. The relabel runs, the server reboots once more, then log in as root with the new password. - Ubuntu/Debian: at GRUB add
init=/bin/bashinstead, thenmount -o remount,rw /,passwd root, andexec /sbin/init(no SELinux relabel). - Afterwards — protect it: give admins personal accounts with
sudo(so the root password is rarely needed), store the root password in a vault, set a GRUB password, and encrypt disks of servers in unsafe places:
grub2-setpasswordCheck that it worked
After the second boot, log in as root on the console (or su - from a user) with the new password, and check SELinux is still enforcing and labels are right:
getenforce
Enforcing
ls -Z /etc/shadow
system_u:object_r:shadow_t:s0 /etc/shadowCommon problems
| Problem | Cause | Fix |
|---|---|---|
| Nobody can log in after the reboot | /.autorelabel was skipped. | Do it again and add touch /.autorelabel; or boot with enforcing=0 once, then restorecon -v /etc/shadow. |
passwd: Authentication token manipulation error | /sysroot still read-only, or not in the chroot. | mount -o remount,rw /sysroot, then chroot /sysroot. |
| GRUB asks for a username and password | A GRUB password is set. | You need that password (or rescue media). |
| No GRUB menu appears | Hidden menu / timeout 0. | Press Esc/Shift early; in the cloud use the serial console. |
| The disk is encrypted (LUKS) | Needs the passphrase first. | You need the LUKS passphrase — without it, no access. |
| Cloud VM without console access | No serial console. | Detach the disk, attach it to a rescue VM, change the password there (and relabel). |
Go further
- Command pages: passwd, grubby, restorecon, getenforce.
- Next how-tos: Create a user with sudo rights, Reset a lost MySQL root password, Find and fix SELinux denials.
- Learn it: RHCSA — Reset the root password, RH134 — rd.break, RH134 — Protect the boot.
- Practise: Lab: break and repair the boot.
1Which step is forgotten most often, and what happens then?
touch /.autorelabel — without it /etc/shadow has a wrong SELinux label and nobody can log in.
2How do you stop others from resetting the root password at the console?
A GRUB password (grub2-setpassword) and disk encryption for servers in unsafe places.