October 21, 2024

How to Reset the Root Password on an Ubuntu VPS

mr rockstar

How to Reset the Root Password on an Ubuntu VPS
Cheap Dedicated Server

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.

  1. Log in to your VPS control panel.
  2. 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.

  1. Reboot your VPS by typing:
     
    sudo reboot

  2. During the boot process, press and hold the Shift key to bring up the GRUB menu.
  3. From the GRUB menu, select Advanced options for Ubuntu.
  4. 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.

  1. Select the root shell option.
  2. 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:
    Remount the File System in Read or Write Mode

 
mount -o remount,rw /

Step 5: Reset the Root Password

Now that the file system is writable, you can reset the root password.

  1. Type the following command to change the root password:
    Reset the Root Password
     
    passwd root

  2. 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.

  1. Type the following command to reboot:
    Reboot the VPS
     
    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

  1. 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.
  2. Select the Ubuntu ISO image to boot from.
  3. Once the system is booted, access the live environment’s terminal.

Step 2: Mount the Root Partition

  1. Identify the root partition of your system using the fdisk or lsblk commands:
     
    lsblk

    Look for the partition that has the root (/) file system.

  2. Mount the root partition to access the system files:
    Mount the root partition to access the system files
     
    sudo mount /dev/sdX1 /mnt

    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:

 
sudo chroot /mnt

Step 4: Reset the Root Password

  1. Now, reset the root password as usual:
     
    passwd root

  2. Enter and confirm the new password.

Step 5: Update the Bootloader (if necessary)

If there are any boot issues, update the GRUB bootloader:

 
update-grub

Step 6: Reboot the VPS

After changing the password, exit the chroot environment:

 
exit

Then, unmount the partition and reboot:
unmount the partition and reboot

 
sudo umount /mnt

sudo 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.

 

What should I do if recovery mode doesn't show the 'root shell' option?

If recovery mode lacks the ‘root shell’ option, you can use a live ISO to mount your root partition and reset the password. This method is typically available in your VPS control panel.

Popular Blog Posts