Reset VPS root password
In this knowledge base article, we assume that you have access to your VPS via SSH. Don't know how to do that? Then take a look at the following article: https://mijn.host/kb/verbinden-met-ssh/
The first step you need to take is to mount the partition in the Rescue mode environment.
You can enter rescue mode as follows:
- Go to VPS in the Control Panel
- Under restart, select the option 'Restart in rescue mode'
To find out which partition it is, you can use the following command:
# lsblk
You should see a similar output:
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
The VPS in question has 20GB of storage. This means that the partition we need to mount is sdb1 because it contains 19.9GB of the storage and therefore also holds the Linux file system. This partition is located in the /dev directory by default.
Note
The name of your partition may differ, so follow the output of your system. In this article, we call it sbd1.
After identifying the storage device, create a root directory within the /mnt directory. Use the mount command to mount the partition in the Rescue mode environment:
# mkdir /mnt/root
# mount /dev/sdb1 /mnt/root
Now navigate to the newly mounted partition and use the chroot command to give yourself root access to the file system:
# cd /mnt/root
# chroot /mnt/root
Now we can change the root password with the following command:
# passwd
If you want to change the password for another user, you can append the command with the username of that user. If you do not specify a username, you change the root password by default.
Exit Rescue mode and restart your server. If all changes have been applied successfully, you can now log in with your new password.
Still have questions? Get in touch.