How Do I Reset the Password for User root in Single-User Mode on a Linux ECS?
Scenarios
This section describes how to reset the password of user root in single-user mode on a Linux ECS.
This section applies to x86 ECSs.
Back up data before resetting the password of user root in single-user mode.
Select a method based on the OS of your ECS.
CentOS 8
- Remotely log in to the ECS
Click Remote Login in the Operation column.
- Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
- When the interface for selecting a kernel appears, press the e key to go to the configuration interface for boot options.
Figure 1 Entering the kernel editing mode
- Edit the boot options.
Change ro to rw init=/sysroot/bin/bash.
Figure 2 Before the change
Figure 3 After the change
- Press Ctrl+X.
Wait for the system to boot into the single-user mode.Figure 4 Single-user mode (emergency shell)
- Run the chroot /sysroot/ command to access the system.
- Run the following command to reset the password of user root:
# passwd root
Figure 5 Resetting the root password in single-user mode.
- (Optional) Run the following command to enable SELinux:
- Run the following command to exit the root directory:
- Run the following command to restart the ECS:
# reboot
CentOS 7 or EulerOS
- Remotely log in to the ECS using the VNC.
Click Remote Login in the Operation column.
- Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
- When the interface for selecting a kernel appears, press the e key to go to the configuration interface for boot options.
Figure 6 Entering the kernel editing mode
For EulerOS, the GRUB file is encrypted by default. When you enter the kernel editing mode, you will be required to enter the username and password. Contact the customer service to obtain them.
- Locate the line containing linux16 and perform the following operations:
- Delete the parameters that do not need to be loaded (from ro to the end).
Retain console=tty0 console=ttyS0 for BMS.
- Change ro to rw for remounting the root partition with read-write permissions.
- Add rd.break and press Ctrl+X.
Figure 7 Before the change
Figure 8 After the change
- Delete the parameters that do not need to be loaded (from ro to the end).
- Run the following command to go to the /sysroot directory:
# chroot /sysroot
- Run the following command to reset the password of user root:
# passwd root
- (Optional) Run the following command to enable SELinux:
- Run the following command to exit the root directory:
- Run the following command to restart the ECS:
# reboot
CentOS 6 or Red Hat 6
- Remotely log in to the ECS
Click Remote Login in the Operation column.
- Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
- After the restart starts, press Esc repeatedly to prevent the system from starting and enter a grub menu.
Figure 9 GRUB menu
- Use the arrow keys to select the first kernel and press e to edit the kernel.
Figure 10 Entering the kernel editing mode
- Select the kernel line and press e again to edit this line.
Figure 11 Selecting the kernel line
- Add 1 to the end of rd_NO_DM.
Figure 12 Adding 1 to the end of the rd_NO_DM
- Delete console=ttyS0,115200n8 and press Enter.
Figure 13 Deleting console=ttyS0,115200n8
- Press b to boot using the kernel and boot into runlevel 1 (single-user mode).
- When the prompt # is displayed, run the following command to reset the password:
# passwd root
- Restart the ECS.
Debian or Ubuntu
- Remotely log in to the ECS
Click Remote Login in the Operation column.
- Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
- After the restart starts, press Esc repeatedly to prevent the system from starting and enter a grub menu.
Figure 14 GRUB menu
- Use the arrow keys to select a kernel and press e to enter the editing mode.
- Locate the line starting with linux, and replace the content from ro to the end of the line with rw init=/bin/bash (remount the root partition with read-write permissions).
Figure 15 Editing boot options
- Press Ctrl+X to enter the single-user mode.
- Run the following command to reset the password of user root:
# passwd root
- Run the following command to restart the ECS:
SUSE 11
- Remotely log in to the ECS
Click Remote Login in the Operation column.
- Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
- Press the up or down arrow key to prevent automatic system startup, and enter the GRUB menu.
- Delete the content following Boot Options and add init=/bin/bash.
Figure 16 Boot options
- Press Enter to enter the single-user mode.
- Run the following command to reset the password of user root:
# passwd root
- Run the following command to restart the ECS:
SUSE 12
- Remotely log in to the ECS
Click Remote Login in the Operation column.
- Click Ctrl+Alt+Del in the upper part of the remote login panel to restart the ECS.
- Press Esc to stop the countdown, and enter the GRUB menu.
Figure 17 GRUB menu
- Use the arrow keys to select a kernel and press e to enter the editing mode.
- Locate the line starting with linux and add init=/bin/bash to the end of the line.
Figure 18 Editing boot options
- Press Ctrl+X to enter the rescue mode.
- Run the following command to reset the password of user root:
# passwd root
- Run the following command to restart the ECS:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.