CentOS 7忘记root密码的解决办法
CentOS 7忘记root密码的解决办法
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112350616-52978204.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112352984-1796069637.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112357641-1891945400.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112359927-179551520.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112350616-52978204.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112402652-1442659439.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112405313-1260652162.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112359927-179551520.png)
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112407179-929218998.png)
CentOS 7&RHEL 7与之前的5,6不同的是,当忘记root密码,并采用GRUB2为启动器时,将无法通过单用户模式重置root密码。
方法1:(推荐)
1、启动系统,在grub菜单选择第一个选项,然后按下e键进入编辑模式。
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112350616-52978204.png)
2、在 linux16 /vmlinuz-3.10.0-327.el7.x86_64 所在行,将ro 改为 rw,同时在行尾添加 init=/bin/sh 语句,如下图所示:
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112352984-1796069637.png)
3、按Ctrl+X 重启,并修改密码
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112357641-1891945400.png)
或
# echo "111111" | passwd --stdin root
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112359927-179551520.png)
4、由于selinux开启着的需要执行以下命令更新系统信息,否则重启之后密码未生效
# touch /.autorelabel
6、重启系统
# exec /sbin/init
或
# exec /sbin/reboot
方式2:
1、启动系统,在grub菜单选择第一个选项,然后按下e键进入编辑模式。
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112350616-52978204.png)
2、在 linux16 /vmlinuz-3.10.0-327.el7.x86_64 所在行,将ro 改为 rw init=/sysroot/bin/sh,如下图所示:
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112402652-1442659439.png)
3、按Ctrl+X 重启,并修改密码
访问系统 chroot /sysroot
重置密码 passwd root
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112405313-1260652162.png)
或
# echo "111111" | passwd --stdin root
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112359927-179551520.png)
4、由于selinux开启着的需要执行以下命令更新系统信息,否则重启之后密码未生效
# touch /.autorelabel
6、退出chroot,并重启系统
# exit //一定要执行exit
# reboot
![](https://img2018.cnblogs.com/blog/533377/201903/533377-20190314112407179-929218998.png)