Skip to content

Instantly share code, notes, and snippets.

@pzbitskiy
Last active July 14, 2024 16:12
Show Gist options
  • Save pzbitskiy/11f16a22fbbec057a8def1aa83501201 to your computer and use it in GitHub Desktop.
Save pzbitskiy/11f16a22fbbec057a8def1aa83501201 to your computer and use it in GitHub Desktop.
Enable SSH for Home Assistant PVE/QEMU virtual machine
# HA VM has dropbear SSH server but it cannot start because there is no authorized_keys
# This scripts adds $SSH_KEY via USB config import.
# All commands run as root on a Proxmox host and checked with PVE 8.2.4 and HAOS 2024.6.4
# 1. Prepare USB stick image
dd if=/dev/zero of=usb-blk.img count=50 bs=4096
losetup -f ./usb-blk.img
# losetup created /dev/loop1
parted -s /dev/loop1 mklabel msdos
parted -s /dev/loop1 mkpart primary 1MiB 100%
mkfs.ext4 -n CONFIG /dev/loop1p1
mount /dev/loop1p1 /root/mnt
echo "${SSH_KEY}" > /root/mnt/authorized_keys
umount /root/mnt
losetup -d /dev/loop1
# 2. Mount the image as USB drive
VMID=100
qm monitor "${VMID}"
# the command above opens QEMU virtual manager CLI
drive_add 0 file=/root/usb-blk.img,if=none,id=drive-usb0,format=raw,cache=none
device_add usb-storage,id=drive-usb0,drive=drive-usb0,removable=on
# check a new usb device created successfully
info usb
quit
# 3. Import the key via VM console in PVE UI
# > ha login
ha os import
systemctl restart dropbear
# ensure dropbear started
systemctl status dropbear
# 4. ssh to the host to port 22222
ssh -p 2222 -i keyfile root@ha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment