CentOS reset root user password

Preface

After using the virtual machine for a long time, I found that I forgot the root password when logging into the system, so I wrote an article here to record the solution to the forgotten root password of CentOS8. After testing, this method is suitable for CentOS7 and CentOS 8 systems to reset. root user password.

CentOS reset root user password
Edit grub menu

First, press the subkeys on the grub interface of the system eto edit the boot menu.

Insert image description here

Modify grub configuration

In the startup menu editing interface, enter the following

rw init=/sysroot/bin/bash

Remember to delete the option linuxin the section ro, or modify it directly as shown below;

Insert image description here

Press Ctrl+x shortcut key to start

Reset root user password

The steps to reset the root password are as follows. Enter the following commands in order to modify the root password.

# 使用 chroot 切换到原有系统
chroot /sysroot
# 修改 root 密码
passwd root
# 这里按照屏幕提示为 root 用户设置新密码
# touch /.autorelabel 是用来重新标记 Selinux 的,如果你开启了的话,建议执行一下
touch /.autorelabel
# 退出
exit
# 重启服务器
reboot

The above process of resetting the password is as shown below;

Insert image description here

After restarting, you can log in using the password modified in the above steps.

Guess you like

Origin blog.csdn.net/weixin_43846408/article/details/131504577