Forgetting or losing the root password for your Ubuntu VPS can seem daunting, but the good news is that you can easily reset it through recovery mode or using a live environment. This guide will walk you through resetting the root password on an Ubuntu VPS.
Method 1: Using Recovery Mode
Most Ubuntu VPS systems come with a recovery mode or “single-user mode,” which allows you to boot into a minimal environment where you can reset the root password.
Step 1: Access Your VPS via Console
First, access the VPS control panel provided by your hosting provider. Most providers offer a web-based console that allows you to access your VPS without needing SSH credentials.
- Log in to your VPS control panel.
- Look for an option to access the VNC or Console to control your VPS.
Step 2: Reboot the VPS into Recovery Mode
Once you have access to the VPS console, you need to reboot the system into recovery mode.
- Reboot your VPS by typing:
- During the boot process, press and hold the Shift key to bring up the GRUB menu.
- From the GRUB menu, select Advanced options for Ubuntu.
- Choose the option that says (recovery mode) next to the Ubuntu version you want to boot.
Step 3: Drop to a Root Shell Prompt
In the recovery menu, you will see several options. Select the one labeled Drop to root shell prompt. This will allow you to access the system as the root user without needing a password.
- Select the root shell option.
- You will now have access to the system with root privileges.
Step 4: Remount the File System in Read/Write Mode
By default, the root file system is mounted as read-only in recovery mode. You need to remount it with write permissions to reset the password.
Run the following command to remount the root file system:
Step 5: Reset the Root Password
Now that the file system is writable, you can reset the root password.
- Type the following command to change the root password:
- You will be prompted to enter a new password. Enter your new root password and confirm it.
Step 6: Reboot the VPS
Once you’ve successfully changed the password, reboot the system.
- Type the following command to reboot:
Your VPS will now reboot, and you can log in with the new root password using SSH or the console.
Method 2: Using a Live CD/ISO (If GRUB Recovery Fails)
In some cases, recovery mode may not be available, or the GRUB menu may not appear. In such situations, you can boot your VPS from a live ISO provided by your VPS hosting provider.
Step 1: Boot from a Live ISO
- In your VPS control panel, look for the option to boot from a live CD/ISO. This will vary depending on the hosting provider, but most offer an option to load a live environment.
- Select the Ubuntu ISO image to boot from.
- Once the system is booted, access the live environment’s terminal.
Step 2: Mount the Root Partition
- Identify the root partition of your system using the
fdisk
orlsblk
commands:Look for the partition that has the root (/) file system.
- Mount the root partition to access the system files:
Replace
/dev/sdX1
with the correct partition.
Step 3: Chroot into the System
To interact with your VPS as if you were booted normally, chroot into the mounted partition:
Step 4: Reset the Root Password
- Now, reset the root password as usual:
- Enter and confirm the new password.
Step 5: Update the Bootloader (if necessary)
If there are any boot issues, update the GRUB bootloader:
Step 6: Reboot the VPS
After changing the password, exit the chroot environment:
Then, unmount the partition and reboot:
You can now log in to your VPS with the new root password.
Conclusion
Resetting the root password on an Ubuntu VPS is a straightforward process that can be done via recovery mode or using a live environment. Always ensure that your root password is securely stored to avoid lockout situations in the future. Additionally, consider using SSH keys for secure access, which eliminates the need to manage passwords altogether.
Reset the Root Password on an Ubuntu VPS (F.A.Q)
What should I do if I can't access the GRUB menu during boot?
If the GRUB menu doesn’t appear, try pressing the Esc or Shift key during boot. If you’re still unable to access it, you may need to boot your VPS from a live ISO through your hosting provider’s control panel.
Will resetting the root password affect my data or configurations?
No, resetting the root password only changes the root user’s password. It does not affect your data, installed software, or system configurations.
Can I reset the root password without console access?
Unfortunately, no. You’ll need console access either through the web-based console provided by your VPS hosting provider or physical access (if applicable) to reset the root password.