必须用rd.break或init=/bin/bash之一:RHEL系(CentOS/Rocky等)优先rd.break,需mount -o remount,rw /sysroot→chroot /sysroot→passwd root→touch /.autorelabel;Ubuntu/Debian等用init=/bin/bash,改ro为rw后直接mount -o remount,rw /→passwd root→exec /sbin/init。

必须有物理或控制台访问权限,远程 SSH 无法操作;重置成功与否,关键取决于你用的是 rd.break 还是 init=/bin/bash —— 两者挂载行为、SELinux 处理、命令路径完全不同,混用必失败。
确认你的发行版和启动方式再选参数
现代 RHEL 系列(CentOS 7/8、Rocky、Alma、Fedora、openEuler)默认使用 dracut + systemd,应优先用 rd.break;Ubuntu、Debian、Kali、Arch 等通用性更强的系统,init=/bin/bash 更稳。
-
rd.break:内核参数行末尾加,同时删掉ro,换成rw rd.break;进入后根文件系统在/sysroot下,只读,需先mount -o remount,rw /sysroot再chroot /sysroot -
init=/bin/bash:在linux16或linux行末尾加,同时把ro改成rw;进入后直接就是真实根目录,/已可写,无需chroot - 别在 Ubuntu 的
ro quiet splash $vt_handoff后只加init=/bin/bash而不改ro→ 会卡在只读挂载,passwd报错Authentication token manipulation error
挂载和密码修改必须按顺序执行
顺序错一步,passwd 就写不进 /etc/shadow。尤其注意 chroot 前后环境差异:
Linux系统管理专家,覆盖12大模块:用户权限、SSH、存储、网络、systemd、防火墙、日志监控、备份恢复、TLS证书、Ansible、容器、IaC。提供配置、验证、加固、监控、备份、自动化、故障排查、回滚闭环。关键词:useradd、sudo、sshd_config、chmod、SEL...
- 用
rd.break时:mount -o remount,rw /sysroot→chroot /sysroot→passwd root(或仅passwd) - 用
init=/bin/bash时:mount -o remount,rw /→passwd root(不能漏root,否则改的是当前 shell 用户,不是 root) - 输入密码时屏幕无任何回显,是正常行为;若输完直接报错,大概率是挂载没成功,用
mount | grep -E "(sysroot|/)$"确认是否含rw
SELinux 开启时必须 touch /.autorelabel
CentOS/Rocky/Fedora 默认启用 SELinux,重置密码后不打标签,下次启动可能卡在 SELinux relabel 阶段,或直接进 emergency mode。
- 无论你用哪种方法,只要系统原本开启 SELinux(
getenforce返回Enforcing),就必须执行touch /.autorelabel - 这个文件必须建在真实根目录下:
rd.break下要在chroot /sysroot后执行;init=/bin/bash下直接在/下执行 - 别写成
touch /autorelabel或touch .autorelabel—— 少了/或点号,无效
重启命令别用 reboot -f 或 shutdown
在救援 shell 里强行断电或用 reboot -f 会跳过 SELinux relabel,导致下次启动失败。
-
rd.break流程:执行exit两次(一次出 chroot,一次出 initramfs),系统自动继续启动并触发/.autorelabel -
init=/bin/bash流程:执行exec /sbin/init(推荐)或exec /sbin/reboot;reboot -f会绕过 systemd,不读/.autorelabel - 看到
Relabeling filesystems...字样滚动,说明 relabel 正在进行,此时等待 2–5 分钟,别强制关机

















