Article directory
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 e
to edit the boot menu.
Modify grub configuration
In the startup menu editing interface, enter the following
rw init=/sysroot/bin/bash
Remember to delete the option linux
in the section ro
, or modify it directly as shown below;
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;
After restarting, you can log in using the password modified in the above steps.