Skip to content

Instantly share code, notes, and snippets.

@smithj33
Last active January 7, 2024 06:26
Show Gist options
  • Save smithj33/dd44789daac8c0bd50abd3151354e1c8 to your computer and use it in GitHub Desktop.
Save smithj33/dd44789daac8c0bd50abd3151354e1c8 to your computer and use it in GitHub Desktop.
Bash script that allows you to access an VM remotely via VNC. With the script, you can easily add / change a VNC port in a VM conf file without needing to install VNC server directly on each VM. This has only been tested for Linux guests on a vanilla Proxmox installation.
#!/bin/bash
# ProxmoxVNC
# Use this script to add a VNC port to a Proxmox virtual machine for remote access.
# To access the VM remotely, enter the VM IP address and the port # shown in the
# output of the script. The port # will always start with 59.
#
# You can save and run this script from anywhere on your system.
# This script has only been tested on Linux guest on a vanilla Proxmox installation.
# https://gist.github.com/smithj33
echo
echo Enter VM#:
read vm
echo
echo "======================================================="
echo
echo Checking if VNC port exists...
echo
if grep vnc /etc/pve/local/qemu-server/$vm.conf
then
port=$(grep vnc /etc/pve/local/qemu-server/$vm.conf | cut -b 20-)
echo "*****************************"
echo "VNC Port $port already exists!"
echo "*****************************"
echo
echo "You can access your VM remotely at <Proxmox IP>:59$port"
echo
echo "======================================================="
echo
echo Would you like to change the port?\(\y/n\)\:
read response
echo
if [[ "$response" = "y" ]]
then
sed -i '/vnc/d' /etc/pve/local/qemu-server/$vm.conf
echo Enter the VNC display# to use\(\2 digits\)\:
read display
echo "args: -vnc 0.0.0.0:$display" >> /etc/pve/local/qemu-server/$vm.conf
echo
echo "You can access your VM remotely at <Proxmox IP>:59$display"
echo
echo "======================================================="
else
echo "Goodbye"
echo
fi
else
echo "No VNC Port found!"
echo
echo Enter the VNC display# to use\(\2 digits\)\:
read display
echo "args: -vnc 0.0.0.0:$display" >> /etc/pve/local/qemu-server/$vm.conf
echo
echo "You can access your VM remotely at <Proxmox IP>:59$display"
echo
echo "======================================================="
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment