How can I manually reset the root password on my Linux VM in recovery?
- Reboot in recovery.
- Login via recovery with user/password being root/recovery or root/defaultrootpassword <-- could be either one, depends on if it was able to set it to the default or not. If recovery does not work, try the default root password listed in the properties of the virtual machine.
fdisk -lTo check for the disk that has the same size as the one this VM has. ex: 50GB, you'll probably see 49.something GB here, but that's the one. Normally it's /dev/vda or /dev/xvda, depends on the distribution. It will also show the partitions, and it will more than likely be the /dev/vda1 partition.
- Mount that disk. I like to create a directory under /mnt for this:
mkdir /mnt/vda1and then mount it like this:
mount /dev/vda1 /mnt/vda1
- Now we need to make that environment usable. We need to bind /proc, /sys, and /dev to that environment. Like this:
mount --bind /proc /mnt/vda1/proc
mount --bind /sys /mnt/vda1/sys
mount --bind /dev /mnt/vda1/dev
- Now we can 'change root' to that environment with
- If we check our
pwd(present working directory), we'll have / because we're in the root of this environment now. Double check you're still root with
whoamiand then you can run
passwdand update the password for the root user. It will not ask for the current password.
exitto leave the environment and go back to the recovery image. Unmount binds and disk
is there as a reminder to make sure you're not in the directory you're unmounting or it won't unmount.
Restart the machine and it should allow you in with the password you've set it to.