Kali on Proxmox, two clicks away from Windows
A Kali VM on Proxmox, opened from Windows with two clicks: noVNC vs RDP vs SPICE, fixing the resolution with a udev rule, an API token that can only open that one VM, and the desktop shortcut that ties it all together.
Contents
- Step zero: update
- Three ways to see a VM's desktop
- If RDP is your pick
- Turning SPICE on
- Problem 1: the resolution ignored the window
- Problem 2: the .vv file vanishes
- A token that only opens this VM
- The Windows shortcut
- Problem 3: two clicks, nothing happened
- Bonus: the memory that went missing
- Where it ended up
I keep a Kali Linux VM on my Proxmox server. It stays on, and I use it from Windows 11. Until now I got in through the Proxmox console in the browser, noVNC, which is fine for emergencies but slow, stuck at a fixed resolution and with no real copy and paste between the two machines.
I wanted the actual desktop, in a decent window, without clicking my way through the web panel every time. This is the road I took, stumbles included, and it works for any Linux VM on Proxmox, Kali or not.
Step zero: update #
Kali is a rolling release,1 so a few months without updates turns into one giant update. The usual, as root:
$ apt update $ apt full-upgrade $ apt autoremove $ apt clean
Source
$ apt update
$ apt full-upgrade
$ apt autoremove
$ apt cleanThat was a little over 1,300 packages and a new kernel, so a reboot came after. One tip: I ran the upgrade as a temporary systemd service instead of straight in the terminal. If the connection drops halfway, the upgrade keeps going. Something along these lines:2
$ systemd-run --unit=kali-upgrade --setenv=DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold full-upgrade $ journalctl -fu kali-upgrade
Source
$ systemd-run --unit=kali-upgrade --setenv=DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold full-upgrade
$ journalctl -fu kali-upgradeThe second command follows the log, and closing it doesn't stop anything.
Three ways to see a VM's desktop #
There are three common ways to look at the desktop of a Proxmox VM from Windows:
| noVNC | RDP (xrdp) | SPICE | |
|---|---|---|---|
| Install in the VM | Nothing | xrdp | spice-vdagent |
| Install on Windows | Nothing (browser) | Nothing (Remote Desktop) | virt-viewer |
| What you see | The VM's real screen | A separate session | The VM's real screen |
| Resolution | Fixed | Follows the window | Follows the window |
| Copy and paste | Clunky | Yes | Yes |
Source
| | noVNC | RDP (xrdp) | SPICE | |-+-------+------------+-------| | Install in the VM | Nothing | xrdp | spice-vdagent | | Install on Windows | Nothing (browser) | Nothing (Remote Desktop) | virt-viewer | | What you see | The VM's real screen | A separate session | The VM's real screen | | Resolution | Fixed | Follows the window | Follows the window | | Copy and paste | Clunky | Yes | Yes |
noVNC is the console in the Proxmox web interface. It needs nothing and it always works, which is exactly why it's the emergency door.
RDP is what Kali's own documentation teaches. It uses the Remote Desktop client that already ships with Windows and feels smooth. The catch is that xrdp opens a new, separate session. It doesn't show the VM's "physical" screen, the one the Proxmox console sees.
SPICE is the protocol Proxmox already speaks. It shows the VM's screen exactly as it is, adjusts the resolution by itself, handles copy and paste and can even redirect USB devices into the VM, depending on the client. On Windows, the client is virt-viewer, also called Remote Viewer.
I picked SPICE, because I wanted to see the screen as it really is.
If RDP is your pick #
For the record, the RDP route on Kali is short. Inside the VM:
$ sudo apt install -y kali-desktop-xfce xorg xrdp xorgxrdp $ sudo systemctl enable xrdp --now
Source
$ sudo apt install -y kali-desktop-xfce xorg xrdp xorgxrdp
$ sudo systemctl enable xrdp --nowThen on Windows, open Remote Desktop Connection (mstsc), type the VM's IP and log in with the Kali user. xrdp listens on port 3389 by default, the same as Windows. Kali's ready-made script moves it to 3390, so if you use it, add :3390 to the address.
Turning SPICE on #
In Proxmox, the VM's display has to be SPICE, which is a QXL video card.3 From the command line:
$ qm set <vm-id> --vga qxl,memory=32Source
$ qm set <vm-id> --vga qxl,memory=32The 32 MB of video memory give room for an ultrawide monitor, and Proxmox's own wiki says 32 is enough for 4K. The change only takes effect after a full shutdown and start of the VM. A reboot from inside isn't enough.
Inside Kali, the SPICE agent is the piece that handles resizing and the clipboard. Kali already ships it, but just in case:
$ apt install spice-vdagentSource
$ apt install spice-vdagentOn Windows, install virt-viewer:
$ winget install RedHat.VirtViewerSource
$ winget install RedHat.VirtViewer(Or grab the "Win x64 MSI" installer from the virt-viewer section of virt-manager.org.)
Now, in the Proxmox web interface: select the VM, open the arrow next to the Console button and pick SPICE. The browser downloads a .vv file, it opens in Remote Viewer, and there's Kali.
Problem 1: the resolution ignored the window #
The screen opened at 1024x768, and maximizing the window only stretched the picture, blurry and soft.
The SPICE agent did receive the new size. Running xrandr inside the VM showed my monitor's resolution marked as "preferred", but Xfce never applied it. Doing it by hand worked:
$ xrandr --output Virtual-1 --autoSource
$ xrandr --output Virtual-1 --autoSo I automated it. When the window size changes, the qxl driver fires a "change" event in udev. A rule catches that event and runs a script that applies the preferred mode.
The rule, in /etc/udev/rules.d/50-spice-autoresize.rules:
ACTION=="change", KERNEL=="card[0-9]*", SUBSYSTEM=="drm", RUN+="/usr/bin/systemd-run --no-block --collect /usr/local/bin/spice-autoresize"The script, in /usr/local/bin/spice-autoresize:
#!/bin/sh
sleep 0.5
for d in /tmp/.X11-unix/X*; do
n=":${d##*/X}"
for a in /var/run/lightdm/root/$n $(getent passwd $(loginctl list-sessions --no-legend | awk '{print $3}' | sort -u) | cut -d: -f6 | sed 's|$|/.Xauthority|'); do
[ -r "$a" ] || continue
outs=$(DISPLAY="$n" XAUTHORITY="$a" xrandr 2>/dev/null | awk '/ connected/{print $1}') || continue
[ -n "$outs" ] || continue
for o in $outs; do DISPLAY="$n" XAUTHORITY="$a" xrandr --output "$o" --auto; done
break
done
doneIn plain words: for every X display running, it looks for a credential that lets it talk to that display (the login screen's, or the logged-in user's .Xauthority), lists the connected outputs and tells each one to use its preferred mode. Then:
$ chmod 755 /usr/local/bin/spice-autoresize $ udevadm control --reload
Source
$ chmod 755 /usr/local/bin/spice-autoresize
$ udevadm control --reloadThe systemd-run in the rule is there because udev kills slow processes it starts itself. This way the script runs outside of it.
I also left the agent running on the LightDM login screen, so the resize works before logging in too. In /etc/lightdm/lightdm.conf.d/50-spice-vdagent.conf:
[Seat:*]
greeter-setup-script=/usr/bin/spice-vdagentNow any window size becomes a real resolution. One detail: the window opens at whatever size Kali was at, and the resolution only changes after maximizing or pressing F11.
Problem 2: the .vv file vanishes #
After connecting, the .vv file disappeared from Downloads. That's on purpose. The file is a single-use ticket: it carries a temporary password that's good for about 30 seconds, plus the line delete-this-file=1, so Remote Viewer deletes it right after reading it.4
That meant every connection needed the web panel: find the VM, click Console, click SPICE. And from another PC, the same thing all over again. I didn't like that. I wanted something fixed, that worked from any PC, without downloading files.
Proxmox doesn't have a fixed SPICE address out of the box. Every connection goes through its SPICE proxy, on port 3128, and the proxy wants that ticket. A fixed port can be forced in the VM's config, which is more or less what Unraid does, but it isn't supported and it leaves the screen open on the network with no password.
The answer that keeps coming up on the official forum is cv4pve-pepper, from Corsinvest. It isn't made by Proxmox, but it's open source, maintained and uses only the official API. It runs on your PC, asks the API for a SPICE ticket with a token and opens Remote Viewer right away. It can also start a stopped VM first, and it has a VNC mode that travels inside the API connection on port 8006, for VMs that don't use SPICE.
Source
digraph pepper {
graph [rankdir=LR, fontname="Helvetica", nodesep=0.35, ranksep=0.45];
node [shape=box, style="rounded", fontname="Helvetica", fontsize=11, margin="0.3,0.1"];
edge [color="#8a8a8a", arrowsize=0.6, fontname="Helvetica", fontsize=10];
icon [label="Desktop icon\n(Windows)"];
pepper [label="cv4pve-pepper"];
api [label="Proxmox API"];
viewer [label="Remote Viewer"];
proxy [label="SPICE proxy"];
vm [label="Kali VM", shape=box3d];
icon -> pepper;
pepper -> api [label="token, port 8006"];
api -> pepper [label="one-time ticket", style=dashed];
pepper -> viewer;
viewer -> proxy [label="port 3128"];
proxy -> vm;
}
A token that only opens this VM #
I didn't want to use an admin account for this. So I created a Proxmox user just for it, with no password (it can't log in to the web interface), and a role with only three privileges, granted only on that VM:
$ pveum role add PepperConsole --privs "VM.Audit,VM.Console,VM.PowerMgmt" $ pveum user add pepper@pve --comment "only opens the Kali screen" $ pveum acl modify /vms/<vm-id> --users pepper@pve --roles PepperConsole $ pveum user token add pepper@pve kali --privsep 1 $ pveum acl modify /vms/<vm-id> --tokens 'pepper@pve!kali' --roles PepperConsole
Source
$ pveum role add PepperConsole --privs "VM.Audit,VM.Console,VM.PowerMgmt"
$ pveum user add pepper@pve --comment "only opens the Kali screen"
$ pveum acl modify /vms/<vm-id> --users pepper@pve --roles PepperConsole
$ pveum user token add pepper@pve kali --privsep 1
$ pveum acl modify /vms/<vm-id> --tokens 'pepper@pve!kali' --roles PepperConsoleA token with privsep 1 doesn't inherit anything from its user, which is why the permission has to be granted to the token too.5 That gotcha is in pepper's documentation. VM.PowerMgmt is there so the shortcut can start the VM when it's off. Without that need, leave it out.
I tested it before trusting it: the token sees only Kali, gets Kali's SPICE ticket and gets a 403 when it tries any other VM. If it ever leaks, the worst anyone can do is open that one VM's screen, and one command revokes it.
The Windows shortcut #
Install pepper:
$ winget install Corsinvest.cv4pve.pepperSource
$ winget install Corsinvest.cv4pve.pepperI created the folder C:\cv4pve, and inside it a file called kali.parm:
--host=<proxmox-ip>,<proxmox-name-on-the-vpn>
--api-token=pepper@pve!kali=<token-secret>
--vmid=<vm-id>
--viewer="C:\Program Files\VirtViewer v11.0-256\bin\remote-viewer.exe"
--start-or-resumeWith two hosts, pepper tries the first one (the home network) and, if it doesn't answer, uses the second (the server's address on the VPN). It works at home and away from it.
Then: right-click the desktop, New, Shortcut, with this target:
cv4pve-pepper @C:\cv4pve\kali.parmDone. Two clicks on the icon and Kali's screen opens. On another PC it's just a matter of installing pepper and virt-viewer and copying kali.parm over. That file holds the token's secret, so it doesn't go to any cloud or Git repository.
Problem 3: two clicks, nothing happened #
pepper is a windowed program on Windows, so when something fails through the shortcut, it shows nothing at all. Running the same command in PowerShell gave the reason away:
Unrecognized command or argument 'Files\VirtViewer'.The space in "Program Files" split the path in two. The fix was quoting the viewer's path in the .parm, as it already is above. Worth remembering: when a shortcut does nothing, run the same command in a terminal and read the error.
Bonus: the memory that went missing #
While I was at it, I bumped the VM from 2 vCPUs and 4 GB to 4 vCPUs and 8 GB, because Burp, Firefox and Metasploit together don't fit well in 4 GB. After booting, Kali saw less than 2 GB. The balloon was to blame: the minimum was set to 2048 MB, and Proxmox was reclaiming the VM's memory.6 I set the minimum equal to the total:
$ qm set <vm-id> --memory 8192 --balloon 8192Source
$ qm set <vm-id> --memory 8192 --balloon 8192Now the VM has its 8 GB the whole time.
Where it ended up #
One icon on Windows opens Kali's real screen, at my monitor's resolution, with copy and paste, at home or away, without touching the Proxmox panel and without downloading files. And the key that makes it happen can open that one VM and nothing else.
Notes
A rolling release has no big versions every couple of years. Packages update continuously, so the system is always the latest, as long as it gets updated often. ↩
systemd-run starts the command as a temporary service, owned by systemd instead of the terminal session. A dropped SSH connection doesn't take it down. The Dpkg options answer config file questions on their own, keeping the current files, since nobody is there to answer them. ↩
QXL is a virtual graphics card designed for SPICE. It's what lets the guest and the viewer agree on resolution and draw the screen efficiently. ↩
Opening the .vv file in a text editor before it gets used shows the whole ticket: the host, the proxy, the temporary password and that delete-this-file line. ↩
Privilege separation keeps a token weaker than its user. With privsep 1, the token only gets what is granted to it directly, so a leaked token can't do everything the user can. ↩
Ballooning lets Proxmox take RAM back from a VM that isn't using it. The balloon value is the floor it can shrink to. With the floor equal to the total, nothing gets taken back. ↩