如何重置CentOS 7的Root密码? 如何重置CentOS 7的Root密码

\u5982\u4f55\u91cd\u7f6eCentOS 7\u7684root\u5bc6\u7801

1-\u5728\u542f\u52a8grub\u83dc\u5355\uff0c\u9009\u62e9\u7f16\u8f91\u9009\u9879\u542f\u52a8
2-\u6309\u952e\u76d8e\u952e\uff0c\u6765\u8fdb\u5165\u7f16\u8f91\u754c\u9762
3-\u627e\u5230Linux16\u7684\u90a3\u4e00\u884c\uff0c\u5c06ro\u6539\u4e3arwinit=/sysroot/bin/sh
4-\u73b0\u5728\u6309\u4e0bControl+x\uff0c\u4f7f\u7528\u5355\u7528\u6237\u6a21\u5f0f\u542f\u52a8
5-\u73b0\u5728\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u8bbf\u95ee\u7cfb\u7edf
chroot/sysroot
6-\u91cd\u7f6e\u5bc6\u7801
passwdroot
7-\u66f4\u65b0\u7cfb\u7edf\u4fe1\u606f
touch/.autorelabel
8-\u9000\u51fachroot
exit
9-\u91cd\u542f\u7cfb\u7edf

\u5982\u679c\u8fd8\u8bb0\u5f97\u79d8\uff0c\u4ee5root\u7528\u6237\u767b\u5f55\uff0c\u6267\u884c passwd\u547d\u4ee4 \u5982\u679c\u5fd8\u8bb0root\u5bc6\u7801\uff0c\u4ee5\u5355\u7528\u6237\u6a21\u5f0f\u767b\u9646\u7cfb\u7edf\uff0c\u6267\u884cpasswd\u4fee\u6539\u5bc6\u7801

以下是centos7重置root密码的方法:
1、开启虚拟机;
2、在弹出这个界面时,按上下键防止页面跳转,选择"CentOSLinux(3.10.0-1160.e17.x8664)7(Core)"并按e;
3、找到rocrashkernel=autoxxx,把ro换成rwinit=/sysroot/bin/sh;
4、使用组合键Ctrl+X进入单用户模式;
5、chroot/sysroot访问系统;
6、passwdroot重新输入新的root用户密码;
7、touch/.autorelabel创建标签文件;
8、exit返回刚刚的单用户模式;
9、reboot重启系统;
10、再次重启,输入刚才重新更改的用户密码就能登录系统了!

CentOS 7&RHEL 7进入单用户方式和重置密码方式发生了较大变化,GRUB由b引导变成了ctrl+x引导。
重置密码主要有rd.break和init两种方法。
rd.break方法:
1、启动的时候,在启动界面,相应启动项,内核名称上按“e”;
2、进入后,找到linux16开头的地方,按“end”键到最后,输入rd.break,按ctrl+x进入;
3、进去后输入命令mount,发现根为/sysroot/,并且不能写,只有ro=readonly权限;
4、mount -o remount,rw /sysroot/,重新挂载,之后mount,发现有了r,w权限;
5、chroot /sysroot/ 改变根;
(1)echo RedHat|passwd –stdin root 修改root密码为redhat,或者输入passwd,交互修改;
(2)还有就是先cp一份,然后修改/etc/shadow文件
6、touch /.autorelabel 这句是为了selinux生效
7、ctrl+d 退出
8、然后reboot
至此,密码修改完成
init方法:
1. 启动系统,并在GRUB2启动屏显时,按下e键进入编辑模式。
2. 在linux16/linux/linuxefi所在参数行尾添加以下内容:init=/bin/sh
3. 按Ctrl+x启动到shell。
4. 挂载文件系统为可写模式:mount –o remount,rw /
5. 运行passwd,并按提示修改root密码。
6. 如何之前系统启用了selinux,必须运行以下命令,否则将无法正常启动系统:touch /.autorelabel
7. 运行命令exec /sbin/init来正常启动,或者用命令exec /sbin/reboot重启

步骤一:开机启动时,在相应内核上按e进入编辑模式
步骤二:找到linux16开头那一行,移动光标到最后,输入rd.break,然后按ctrl+x
步骤三:重新挂载/sysroot可读写,mount -o remount,rw /sysroot
步骤四:切换chroot /sysroot
步骤五:更改root密码,echo "密码" | passwd --stdin root
步骤六:重启时selinux对系统relabel,touch / .autorelabel,没开selinux就不需要这一步
步骤七:退出exit
步骤八:重启reboot

扩展阅读:磁盘centos 7安装教程详细 ... centos7永久修改时间 ... centos7重置root密码 ... centos 7进入维护模式 ... linux修改root密码指令 ... centos6.5重置root密码 ... centos7忘了root密码 ... 怎么把centos 设置成中文 ... centos改密码 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网