Skip to content

Instantly share code, notes, and snippets.

@ipcjk
Forked from tpaskhalis/ssh_ubuntu_cloud
Created March 11, 2019 12:08
Show Gist options
  • Save ipcjk/da2725639f59c70d3b3909990f5cbee5 to your computer and use it in GitHub Desktop.
Save ipcjk/da2725639f59c70d3b3909990f5cbee5 to your computer and use it in GitHub Desktop.
Adding ssh public key to Ubuntu cloud image
# Instructions for working with QEMU image come from
# https://www.kumari.net/index.php/system-adminstration/49-mounting-a-qemu-image
1. Download image http://cloud-images.ubuntu.com/
2. Install qemu, nbd-client
3. Load the module
sudo modprobe nbd max_part=8
4. Connect image
sudo qemu-nbd --connect=/dev/nbd0 Downloads/xenial-server-cloudimg-amd64-disk1.img
5. Mount image
sudo mount /dev/nbd0p1 /mnt/cd
6. Add the content of ~/.ssh/id_rsa.pub to /mnt/cd/home/ubuntu/.ssh/authorized_keys
7. Unmount image
sudo umount /mnt/cd
8. Disconnect the image
sudo nbd-client -d /dev/nbd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment