忘记 Linux root 密码时,可通过 GRUB 引导进入单用户模式重置。以下为详细操作步骤。
default=1 timeout=10 splashimage=(hd0,2)/grub/splash.xpm.gz hiddenmenu title Fedora root (hd0,2) kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/VolGroup00/LogVol00 rhgb quiet initrd /initrd-2.6.23.1-42.fc8.img title Windows rootnoverify (hd0,0) chainloader +1
[e] 进入编辑。kernel /vmlinuz... ro root=... rhgb quiet 行,按 [e] 编辑,行尾加 single 进入单用户模式。[Enter] 确认,再按 [b] 引导。系统进入单用户模式。sh-3.2# 提示符(单用户模式仅 root 可用,类似 Windows 安全模式)。/etc/passwd:将首行 root:x:0:0:root:/root:/bin/bash 改为 root::0:0:root:/root:/bin/bash(删去 x)。/etc/shadow:将首行密码哈希值删除,改为 root::13928:0:99999:7:::。:wq! 强制保存。适用于本地物理访问场景,请妥善保管密码保障安全。重置后建议立即为 root 设置强密码。