遺忘 root 密碼是常見急救情境。本文針對 LILO 與 GRUB 兩種開機載入程式,提供進入單用戶模式清空密碼的標準操作流程 (於 Red Hat 8 測試通過)。
lilo: 提示時,輸入:linux singlevi /etc/shadowroot:...,刪除第一個 : 到第二個 : 之間的加密雜湊字串,使其變為 root::... (密碼為空)。:wq),執行 reboot 重啟。passwd 設定新密碼。e 進入編輯模式。kernel 開頭的那一行 (如 kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/),按 e 編輯。single (或 1),結果範例:kernel /boot/vmlinuz-2.4.18-14 single ro root=LABEL=/b 啟動,進入單用戶模式。/etc/shadow 清空 root 密碼欄位,reboot 重啟設定新密碼。linux rescue 進入救援模式。mkdir /mnt/hd && mount /dev/hdaX /mnt/hd (X 為根分區號)。chroot /mnt/hd 切換根環境。passwd root 直接設定新密碼 (比手改 shadow 更安全)。exit 退出 chroot,reboot。mount -o remount,rw /。e,找 linux / linux16 / linuxefi 行尾加 rd.break 或 single,Ctrl+x 啟動,進入後 mount -o remount,rw /sysroot、chroot /sysroot、passwd、touch /.autorelabel (SELinux)、reboot。grub-md5-crypt) 防止未授權進入單用戶模式。