So, I presently use Ubuntu 14.04 as my main operating system. However, I like to keep virtual machine instances of other operating systems like Cent OS, Fedora, Linux Mint and even Ubuntu itself. I use these mostly for development and such work-related stuff. However, I forgot the password to my account on a new Ubuntu virtual machine that I created using KVM (Kernel Virtualization Module), a popular virtualization program. It took me a while to solve this problem. So, if you have this problem too, I want to save you a lot of time and effort by showing you how to solve it.
- Make sure your Ubuntu VM is powered off when you start the steps below.
- Try as much as possible to have access to the Internet.
Step 1: Boot into GRUB’s boot menu
Launch KVM and power on your desired Ubuntu VM. Watch the screen closely and as soon as you see any text or output on it, start tapping the rightside Shift key. The boot screen flies by on KVM, so tap that Shift key as fast as possible. If you succeed, you will see the GRUB menu (see screenshot below). If you don’t succeed in getting to the GRUB menu, then just switch off your VM and try this step again. (Note: if you try 2 or 3 times and don’t succeed, try using the leftside Shift key on your keyboard.)
Step 2: Boot into Ubuntu’s recovery mode
You can access the root user for your machine from GRUB. Simply use your arrow keys to scroll to “Advanced options for Ubuntu” in the first GRUB menu and hit Enter/Return. On the next page, highlight the option that ends with “recovery mode”. Use the Enter key to choose this option and proceed to the next step.
Step 3: Obtain a root shell
You should now be in the Ubuntu recovery mode. Use the arrow keys on your keyboard to scroll to the “root Drop to root shell prompt” option and hit Enter/Return. This will fire up a terminal with root user privileges for your Ubuntu KVM instance.
Step 4: Mount the root file system
Next, you need to mount the root file system using:
mount -o remount, rw /
Step 5: Reset the password of the desired account
So, let’s say you want to reset the password for your account with a username of johndoe. The following command is the magic wand that will finally get the job done:
After entering that command, you will be prompted twice to enter your new password. Make sure you choose a new, strong password that has lowercase letters, uppercase letters, numbers and punctuation marks in it WHILE being easy to remember FOR YOU.
In case you don’t remember your user username, you can ask the passwd program to list all user accounts on the computer for you by entering:
Note that this will print a LONG list of users. Just use Shift + Page Up to scroll up the output or Shift + Page Down to scroll down and find your desired username. However there’s a shorter, almost poetic way to view all passworded accounts on your VM:
passwd -Sa | grep P
Step 6: Reboot the system and voila!
Now that you’ve reset the password for the
johndoe account, you need to reboot your Ubuntu virtual machine. You can do this while still in the root command prompt by using this command:
Wait for your VM to reboot and land you on the login page. Enter the new password for johndoe that you set in the steps above and boom! You have regained access to your account on your Ubuntu VM instance.
Here’s one piece of advice though: as much as possible, try to make your password hard to crack BUT easy for you to remember.
Thanks a lot for reading!