Whether on our cell phones or our personal computers, we have all had that feeling of being locked out of a device. But what if instead of being locked out of your phone you were locked out of the tool you use to run your website or house your important data? That could cost you a lot of money in addition to the normal frustration. But fear not. In this article, we will show you how to recover your root password using Rescue Mode on an OVHcloud VPS.
Note: If you wish to set a root password for SSH access, please be advised that this is not the safest security practice. To learn more about how to access your VPS via SSH securely, please check out the "How to Secure Your SSH Connection" articles for Ubuntu 18.04 and CentOS 7 in our Server Administration articles section.
Booting Your Server in Rescue Mode
Since we don't have physical access to the server to change our root password, we will access the server using Rescue Mode. To do so, first log into the OVHcloud Manager. Click the VPS drop-down on the left-hand sidebar and select your VPS from the menu. Then, click the Reboot in rescue mode button.
Once you have rebooted, it will take about three minutes for your server to be accessible again. Rescue mode credentials will be emailed to your primary email address associated with your OVHcloud account. You will be able to SSH into the server using these credentials. Next, we will take a look at how to mount the partition and change the root password to regain access to the server.
Mounting the Partition and Changing Root Password
Once you have successfully accessed your VPS via SSH, the first step will be to mount the partition to the Rescue Mode environment. We can find out which partition we need to mount using the following command:
Here is a sample output of this command:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 2.5G 0 disk
└─sda1 8:1 0 2.5G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 19.9G 0 part
├─sdb14 8:30 0 4M 0 part
└─sdb15 8:31 0 106M 0 part
This VPS has 20 GB of storage space. That means that the partition we need to mount is
sdb1 since it contains 19.9 GB of storage and thus, contains the Linux filesystem. This partition will be in the
/dev directory by default.
After identifying the storage device, create a root directory within the
/mnt directory, and then use the
mount command to mount the partition to the Rescue Mode environment:
# mkdir /mnt/root
# mount /dev/mdX /mnt/root
Now, navigate to the newly mounted device and then use the chroot command to give yourself root access to the mounted filesystem:
# cd /mnt/root
# chroot /mnt/root
Now, we are able to change the root password using the following command:
If you wish to change the password for a different user just append the username to the end of the above command and it will change the password for that user. If you don't specify a user, as we did above, you are changing the root password by default.
Exit Rescue Mode and reboot your server. If you did everything correctly, your new password will grant you access to your live server environment.
Rescue Mode makes losing your password a minor annoyance at worst, rather than the catastrophe it could have been. In this article, you learned how to access Rescue Mode, mount the correct partition for your Linux filesystem, and change a user's password to regain access to your VPS.