Resetting a forgotten root password on CentOS 7

Linux CentOS 7[edit]

Reboot the Linux CentOS 7 system, then use the arrow keys to select the corresponding system in the screenshot below and press the “e” key.

CentOS1.png

The following screen appears; press the down arrow key to move the blue-highlighted box, and pay attention to the last part inside that box.

CentOS2.png

Press “ctrl+e” to move to the end, delete “rhgb quiet LANG=zh_CN.UTF-8”, type “init=/bin/sh”, and press “ctrl+x” to boot the system.

CentOS3.png

Type “mount -o remount, rw /“ and press Enter to make the filesystem writable.

CentOS4.png

Type “passwd” to change the password (you have to enter it twice). On success you’ll see the following prompt: all authentication tokens updated successfully.

CentOS5.png

Type “touch /.autorelabel” to make sure the system recovers correctly after the reboot.

CentOS6.png

Type “exec /sbin/init” to reinitialize.

CentOS7.png

The system starts initializing, and once it’s done it reboots automatically — just log in with the new password.

CentOS8.png Reposted from http://www.ytyzx.net/index.php/%E5%A6%82%E4%BD%95%E6%81%A2%E5%A4%8D%E6%88%96%E9%87%8D%E7%BD%AEFreeBSD_%26_Linux%E7%9A%84root%E5%AF%86%E7%A0%81