I am trying to create a cloud-init configuration file to inject my own SSH keys into the "ubuntu" user for a Multipass instance. I have managed to successfully inject my SSH key when I create a new user for myself and set the SSH key for that user. However, the SSH key for the "ubuntu" user disappears in the process. How should I structure the YAML file so that the "ubuntu" user remains unchanged and I can still access the machine using SSH?
Here is my example cloud-init YAML file:
#cloud-config
users:
- default
- name: vmuser
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- ssh-rsa AAAAB3Nza....
output:
all: ">> /var/log/cloud-init-output.log"
Additionally, I have tried using the runcmd and echo commands to directly set the SSH key in the authorized_keys file, like so:
runcmd:
- sudo echo "ssh-rsa AAAAB3Nza..." >> ~/home/ubuntu/.ssh/authorized_keys
However, this does not work.
Any help or guidance on how to achieve this would be greatly appreciated. Thank you!