Skip to content

Instantly share code, notes, and snippets.

@styk-tv
Forked from ipcjk/ssh_ubuntu_cloud
Created January 6, 2025 10:32
Show Gist options
  • Save styk-tv/7f551afa26d01f6ac8d44b67874f3278 to your computer and use it in GitHub Desktop.
Save styk-tv/7f551afa26d01f6ac8d44b67874f3278 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