Set VNC password with hook script not working

mriley

New Member
Apr 15, 2026
2
1
3
When I reboot my Proxmox host, I have to enter this command in the Monitor section of the VM in order to set a password for VNC (necessary to connect with the VNC client built into macOS).

Code:
set_password vnc none -d vnc2

This does the trick but I want to automate it. Looks like a hook script should do it. Modifying the post-start section of the example script, I have this but it doesn't seem to work.

Code:
...
elsif ($phase eq 'post-start') {

    # Second phase 'post-start' will be executed after the guest
    # successfully started.

    # VNC through Proxmox host to set password for macOS clients
    "set_password vnc none -d vnc2";

    print "$vmid started successfully.\n";
...

What am I doing wrong? I have the script set to the VM I'm starting (the "qm set <vmid> --hookscript ..." command returns no errors).

Thanks for any help you can offer. Been banging my head against the desk for far too long for something that seems like it should be simple. :)
 
Hi,

Perl isn't shell scripting - to run external commands, you need to execute them explicitly.
For example, this Stack Overflow posts shows a few different ways: https://stackoverflow.com/a/3200810

So I'd recommend doing the following, if you just want to run the command:
Code:
elsif ($phase eq 'post-start') {

    # VNC through Proxmox host to set password for macOS clients
    qx/set_password vnc none -d vnc2/;

    print "$vmid started successfully.\n";

FWIW; the hook scripts are not limited to Perl, you can use any language you want, e.g. also bash.
 
I have to enter this command in the Monitor section of the VM
So the command has to be entered WITHIN the VM? The suggested hook-scripted commands are not doing that.
Your going to need a Guest agent command or SSH etc. to get that command to run within the VM.
 
So the command has to be entered WITHIN the VM? The suggested hook-scripted commands are not doing that.
Oh right, yeah, didn't read that!

Although then it would be possible to use pvesh create /nodes/<hostname>/qemu/<vmid>/monitor -command='set_password vnc none -d vnc2' as command instead, that would do the trick.
 
I was able to modify your suggestions and got a working solution for my setup. Thank you!

Code:
...
elsif ($phase eq 'post-start') {

    # VNC through Proxmox host to set password for macOS clients
    system("pvesh create /nodes/px-node-02/qemu/104/monitor -command='set_password vnc none -d vnc2'");
...
 
  • Like
Reactions: cheiss