Centos7 忘记密码解决方法

时间:2022-01-03 00:40:51

一.Centos7 忘记密码解决方法

1.进入单用户模型

重启 Linux 系统主机并出现引导界面时,按下键盘上的 e 键进入内核编辑界面

Centos7 忘记密码解决方法

然后按向下键,找到以“Linux16”开头的行,在该行的最后面输入“init=/bin/sh”

Centos7 忘记密码解决方法

输入以后就按 ctrl + x  进入单用户模式

Centos7 忘记密码解决方法

2.修改密码

依次输入以下命令,等待系统重启操作完毕,然后就可以使用新密码来登录Linux 系统了

mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit reboot

Centos7 忘记密码解决方法

3.重启

最后reboot重启

使用新密码进入

Centos7 忘记密码解决方法

二.root用户密码修改

passwd root      # 密码修改命令

Centos7 忘记密码解决方法