How to Reset the Password of Ubuntu Running on KVM

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

Step 2 - How to reset the password of an ubuntu account in kvm-

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

Step 3 - How to reset the password of an ubuntu account in kvm- Once in GRUB Recovery Menu, scroll down to the "root Drop to root shell prompt" option and hit enter. Then, at the bottom of the screen, you will see a command prompt with root privileges.

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

Step 4 - How to reset the password of an ubuntu account in kvm- In the root command prompt, enter the following command: mount -o remount, rw /

Next, you need to mount the root file system using:

mount -o remount, rw /


Step 5: Reset the password of the desired account

Step 5 - How to reset the password of an ubuntu account in kvm- Let's assume your account name is johndoe. So, after mounting your root partition, enter the followng command to reset the password for a user named johndoe: passwd johndoe. You will be prompted twice to enter your new password, and make sure you choose a strong one that has numbers, punctuation marks and upper and lowercase letters. Then reboot.

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:

passwd johndoe

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:

passwd -Sa

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!

Step 6 - How to reset the password of an Ubuntu account in KVM

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:

reboot now

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!

Drop a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.