If you've lost access to the root password on a Linux server and can't log in through VNC, you can reset the root password using a recovery method. Here are the steps you should follow:
Step 1: Reboot into Recovery Mode
- Stop or Reboot the Server:
- Shut down or reboot your server through the hosting provider's control panel. In some cases, you may need to request technical support for access to the recovery console.
Step 2: Connect to the Recovery Console
- Use a VNC Client:
- Connect to the recovery console provided by your hosting provider using a VNC client. This may require a special link or instructions from the service provider.
Step 3: Mount the Root Filesystem
- Mount the Filesystem:
- Once connected to the recovery console, mount the root filesystem. Typically, this can be done with the following command (the device name might differ):
bash
mount /dev/sda1 /mnt
- Once connected to the recovery console, mount the root filesystem. Typically, this can be done with the following command (the device name might differ):
Step 4: Change Root Directory
- Change Root Directory:
- Use the
chroot
command to change the root directory to the mounted filesystem:bashchroot /mnt
- Use the
Step 5: Reset the Root Password
- Use the
passwd
Command:- Reset the root password using the following command:
bash
passwd root
- The system will prompt you to enter a new password twice. Enter and confirm the new password.
- Reset the root password using the following command:
Step 6: Reboot the Server
- Exit and Reboot:
- Exit the recovery mode and reboot the server to apply the new root credentials:
bash
exit reboot
- Exit the recovery mode and reboot the server to apply the new root credentials:
Notes
- Ensure you use this method only if there is no other way to regain access to the server.
- After successfully resetting the password, update your security settings and ensure the new password is secure.
- These steps may vary depending on your hosting provider and server configuration. If you encounter difficulties or have questions, contact your service provider’s technical support or consult a qualified system administrator.