How can I access a VM when the SSH daemon no longer works?
If you have a running virtual machine, but have lost the access via SSH to it, you are in general not able to access it anymore. The cloud images we use don't provision a user with a password, so you can't even fix things via the console. However, there is a workaround:
- Create a Snapshot of the VM
- Configure a new VM to launch from that Snapshot
- Setup specific Cloud-Init configuration to setup a new user in the VM
- Boot the copied VM
Create a Snapshot of the VM
Go to the list of your running instances, and select the action Create Snapshot
Give the snapshot a name and wait for the snapshotting to finish. Your Snapshot will show up in the Images & Snapshots tab
Configure a new VM to launch from the Snapshot
When the snapshotting is done, you can Launch a new VM from that snapshot. Configure the new VM as you had the original VM.
Setup specific Cloud-Init configuration to setup a new user in the VM
In the Post-Creation tab, enter a YAML file that looks like this:
- name: joe
gecos: Joe Doe
The passwd is the hashed value of the password you want the user to have. It is easiest if you copy that value from an existing /etc/shadow file where that user with the password already exists.
Boot the copied VM
Now Launch the VM. You can now use the console through the GUI to access the machine and fix whatever needs to be fixed.
You can now terminate the first VM, as it is no longer needed (and will not be accessible in the future) and use the new VM instead.