Linux CentOS 7 重置root用户密码
1.进入单用户模式
系统启动读秒的时候,按下e编辑当前内核:
linux16 /vmlinuz-3.10.0-514.el7.x86_64 root=/dev/mapper/cl-root ro cra\ shkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet LANG=en_US.UTF-8
修改为:
linux16 /vmlinuz-3.10.0-514.el7.x86_64 root=/dev/mapper/cl-root ro cra\ shkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap init=/bin/sh
将“rhgb quiet LANG=zh_CN.UTF-8”替换为“init=/bin/sh”,按“ctrl+x”或“F10”引导系统。
2.挂载并使文件系统为可写
sh-4.2 # mount -o remount,rw /
sh-4.2 # echo NewRenwole123 | passwd --stdin root
Changing password for user root.
passwd:all authentication tokens updated successfully.
3.加载 SELinux 策略,并重启系统
sh-4.2 # touch /.autorelabel sh-4.2 # exec /sbin/init
系统初始化完毕后会自动重启,用新密码登录即可。
摘录自:https://renwole.com/archives/482