centos7.6 reset root password

How to reset root password when forgetting it?

1. View the version information of the current system

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

You can see that the system version is centos7.6

2. When restarting the Linux system host, keep pressing the up or down arrow keys, and when it stays on the boot interface, press the e key on the keyboard to enter the kernel editing interface

 Currently it is the boot interface, and the following prompt also has the e key to enter the kernel editing interface

 3. Press the arrow keys to find, find the position "LANG=zh_CN.UTF-8", then add rw single init=/bin/bash at the back, and then press Ctrl + X to run the modified kernel program, automatically reboot

 The following is modified

 Press Ctrl + X to reboot

Automatically stay on the bash interface, follow the steps below to execute the command

--------- Execute the command [passwd] to reset the root password

---------- If SELinux is enabled, execute the command " 【touch /.autorelabel】 ", this command must be executed, otherwise an error will be reported after restarting. (This command can also be executed in the closed state, so to avoid errors, it is best to execute the following command regardless of whether it is turned on or off)

---------- Finally, execute the command [exec /sbin/init] to restart the computer

---------- When the following interface appears, press  ctrl+d    to restart

 Finally enter the normal login interface

If it is a RHEL8.0 system, please refer to the following steps

When entering the boot interface, add the rd.break parameter at the end of the linux parameter line, and then press the Ctrl + X key combination to run the modified kernel program

 When entering rescue mode, enter the following commands in sequence, and then press Ctrl + D twice to exit and restart. After the system restarts again, you can use the new password to log in to the Linux system

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

Guess you like

Origin blog.csdn.net/weixin_42517271/article/details/128527826