Starting a virtual machine image without knowing the user name or password



I have a virtual machine image in openstack. It is running ubuntu. I used it in a class about a year ago, but I have forgotten the password, and even the user name (but I do remember they were chosen to be secure). I also remember that the ubuntu user was removed and root logins were disabled, specifically to make the machine hard to attack. I can launch the machine and get the login prompt, but I can’t sign in without credentials. What can I do?


I found the solution! When launching the image, there’s a “Post-Creation” tab that lets you specify a script to run after the machine is launched, see below

If you pick direct input, you can type (or paste) a shell script into a text box and have it run once when the machine is launched. I had it create a user called temporary and a password called temporary. The password must be changed on the first login. The user has sudo rights, so can view which user accounts exist, change passwords to a known value, look at files, or whatever.


useradd -m -U -G adm,dialout,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev -s /bin/bash $USERNAME
echo “$USERNAME:$PASSWORD” | chpasswd
chage -d 0 $USERNAME


Remember not to apply the following directly to your VM! Test it first on a clone or a backup image before applying it to your production VM.

It depends on your installation, but in general you should be able to do this by booting into rescue mode (you can select this as the machine is booting up). This will give you a shell, remount the file system with read/write (it’s read only at this point). Then you will be able to edit the shadow file and delete root/user hashed password and reboot.