Home >Operation and Maintenance >Linux Operation and Maintenance >How to change root password in centos
How to change the root password in centos
If you know the root password, you need to change the password
Log in to the system as root and enter the passwd command to change the root password by default, and then enter the password twice.
Recommended: "Linux Tutorial"
Application Scenario
The Linux administrator has forgotten the root password and needs to retrieve it.
Note: This article is based on the centos7 environment. Since the versions of centos are different, please confirm the version before continuing.
Operation steps
1. Restart the system. During the boot process, quickly press the ↑ and ↓ arrow keys on the keyboard. The purpose is to inform the bootstrap that we need to select a different action on the bootstrap page in order to cause the bootstrap to pause.
The following is the interface after pause. You can check the English below to know the functions of ↑ and ↓.
2. Use ↑ and ↓ to set the selected line to the first line (the background is highlighted to indicate selection), press e on the keyboard to enter the editing mode
3. Move the cursor to the space after .UTF-8, and then append init=/bin/sh. Pay special attention here, you need to write it after UTF-8, keep it on the same line, and pay attention to spaces. Because the screen is too small, line breaks will be added automatically. This is normal.
4. Press CTRL
1. Mount the root directory
mount -o remount, rw /2. Select the user name whose password you want to change. Here, select the root user to modify it. You can change it to the user you want to modify
passwd root3. Enter the same new password twice. Note that no characters will appear on the screen when entering the password. If the password entered is too simple, a warning will be prompted (BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic). You can ignore it and continue to enter the password, but it is recommended to set it more complicated. Password to ensure security4. If SElinux has been turned on, you need to enter the following command
touch /.autorelabel5. Finally, enter the following command to restart the system
exec /sbin/init 或 exec /sbin/reboot
The above is the detailed content of How to change root password in centos. For more information, please follow other related articles on the PHP Chinese website!