Skip to content

Instantly share code, notes, and snippets.

@tpaskhalis
Last active December 19, 2022 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tpaskhalis/1e601200da499508f9a8502493091f52 to your computer and use it in GitHub Desktop.
Save tpaskhalis/1e601200da499508f9a8502493091f52 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