How to reset your Linux root password
In case you lost access to your server due to a forgotten root password, you can use our rescue system to reset it.
Prerequisites
Your server must be in rescue mode. That means that a live linux has been booted on your server, and you have already mounted your server's boot disk in a temporary path to be able to access the disk to read from and write to it.
Follow our tutorial on how to access your server's data in rescue mode to get to that point.
Switch into the mounted operating system
You can switch to your mounted operating system by using the following command.
chroot /target
If you've followed the tutorial mentioned above, the command will work out of the box. In case you have mounted your operating system somewhere else, you might need to replace /target
with the path you mounted your server's boot disk to.
By running the command, you will "change root" (hence the name chroot
) into the operating system that is located on the mounted disk. That circumvents any authentication measures and gives you immediate full administrative access.
Change your password
Now that you're in your mounted operating system, use the following command to change your password:
passwd
Select a new, safe and unique password with at least 8 characters or more.
Exit the mounted operating system
That's already it! You can now exit the operating system by pressing CTRL + D or simply running the command exit
.
Unmount your operating system
As you have made changes to the underlying disk of your server, it's highly recommended that you gracefully unmount the disk after you have exited the chroot
environment.
To do so, please follow our tutorial on how to access your server's data in rescue mode where the unmounting process is explained in detail.