SSH Access to Proxmox VM via QEMU Guest Agent
An aide memoire piece
Setting up SSH access to a Proxmox VM requires the QEMU guest agent for remote command execution. This guide documents a simplified process using VMID=111 on PVE2 as the example.
Prerequisites
- Proxmox node SSH access (PVE2: 10.140.3.20)
- Running VM (VMID=111, Debian 12, 10.140.0.208)
- SSH key on the Proxmox node
Step 1: Connect to Proxmox Node
ssh root@10.140.3.20
Step 2: Install QEMU Guest Agent on VM
Run the install command in the VM using qm guest exec:
qm guest exec 111 -- sh -c 'apt-get update && apt-get install -y qemu-guest-agent && systemctl enable qemu-guest-agent && systemctl start qemu-guest-agent'
Step 3: Install and Configure SSH on VM
Once the guest agent is running, install SSH:
qm guest exec 111 -- sh -c 'apt-get install -y openssh-server openssh-client && systemctl enable ssh && systemctl start ssh'
Step 4: Enable Public Key Authentication
Configure SSH to accept public key authentication and allow root login, by default it is disabled:
qm guest exec 111 -- sh -c 'sed -i "s|#PubkeyAuthentication yes|PubkeyAuthentication yes|" /etc/ssh/sshd_config && sed -i "s|#PermitRootLogin prohibit-password|PermitRootLogin yes|" /etc/ssh/sshd_config && systemctl restart ssh'
Step 5: Add SSH Key to Authorised Keys
Get Proxmox node's SSH public key:
cat ~/.ssh/id_rsa.pub
Add to VM's authorized_keys (replace the key below with your actual key) directory:
qm guest exec 111 -- sh -c 'mkdir -p /root/.ssh && echo "ssh-rsa AAAAB3NzaC1yc2E... your-key-here..." >> /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys'
Step 6: Verify SSH Access
Test the connection:
ssh root@10.140.0.208 'hostname && whoami'
Expected output:
localhost
root
Complete Workflow
One-line reference after initial setup is complete, SSH directly to the VM:
ssh root@10.140.0.208 'command-here'
Or from your workstation via the Proxmox node:
ssh root@10.140.3.20 "ssh root@10.140.0.208 'command-here'"
Troubleshooting
SSH Connection Refused: Ensure guest agent is running and SSH service is active.
qm guest exec 111 -- systemctl status ssh
Permission Denied (publickey): Verify authorized_keys has correct permissions (600) and contains your SSH public key.
qm guest exec 111 -- cat /root/.ssh/authorized_keys
QEMU Guest Agent Not Running: Install guest agent first (Step 2) before attempting guest exec commands.
qm status 111
C'est tout! That's all folks.
Matthew
No comments:
Post a Comment