centos7 正确的重置密码姿势

本文介绍如何在CentOS 7系统中进入单用户模式并修改root用户的密码。涉及的操作包括通过GRUB启动菜单临时调整启动选项、使用mount命令进行文件系统重挂载以及通过touch命令触发自动重新标记文件系统标签。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 参考 http://www.centoscn.com/CentOS/config/2014/0829/3595.html

  • 重启,grub界面按“e”临时修改grub

  • 在grub第一个菜单的最下面有一行是关于kernel的,在最后加上“single init=/bin/bash”,然后ctrl+x启动
  • mount可以查看当前是ro的,所以我们需要rw, mount -o remount,rw /
  • echo pass | passwd root –stdin, 注意,这个地方不能直接重启,需要touch /.autorelabel, 因为这个是7,不是6,所以需要touch一下这个文件,至于为啥,我暂时不知道
  • 可以重启了,不过重启exec /sbin/init或者 exec /sbin/reboot之后,我的虚机都是在有几个键闪动,只得从宿主机直接重置。

重点是 autorelabel。

扩展:

啥叫centos7的autorelabel,

Next time when you will reboot the system, it will relabel the filesystem for SElinux automatically.

This usually occurs when labeling a file system for SELinux for the first time, or when switching between different types of policy, such as changing from the targeted to the strict policy.

参考:
http://serverfault.com/questions/432531/what-does-the-autorelabel-file-do-in-linux

扩展:

  • centos6 修改密码,无需touch /.autorelabel。

  • centos 7 如果touch还是不行,可以加上下面的第一行

# genhomedircon
# touch /.autorelabel
# reboot 
  • 另外,一些资料显示,关闭selinux之后就无需touch那个文件了,据我观察,不行哦。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值