遺忘 root 密碼無需重裝系統,透過 GRUB 引導參數掛載根分區為讀寫模式即可重置。適用於 GRUB Legacy 與 GRUB 2。
e 進入編輯e 編輯init=/bin/bash,按 Enterb 啟動,直接進入 root Shellelinux 或 linux16 開頭的行,行末加入 rd.break 或 init=/bin/bashCtrl+x 啟動,進入急救 Shellmount -o remount,rw /sysroot(或 /)chroot /sysroot# 確保根分區可寫
mount -o remount,rw /
# 修改 root 密碼
passwd root
# 輸入兩次新密碼
# 同步磁碟並重新掛載唯讀
sync
mount -o remount,ro /
# 重啟
reboot
重置密碼後,需重新標記安全上下文:
touch /.autorelabel
# 重啟時會自動執行 restorecon -R /
GRUB 選單選中啟動項按 e,在 kernel 行末加 single 或 1,啟動後同樣進入 root Shell,後續步驟相同。