Configure VNC passwords

To manage access to the graphical output of a virtual machine (VM), you can configure a password for the VNC console of the VM.

Before you begin

  • The VM that you want to protect with a VNC password has VNC graphics configured.

    To ensure that this is the case, use the virsh dumpxml command as follows:

    # virsh dumpxml <vm-name> | grep graphics
     <graphics type='vnc' ports='-1' autoport='yes' listen='127.0.0.1'>
     </graphics>

About this task

With a VNC password configured on a VM, users of the VMs must enter the password when attempting to view or interact with the VNC graphical console of the VMs, for example by using the virt-viewer utility.

Important

VNC passwords are not a sufficient measure for ensuring the security of a VM environment. For details, see QEMU documentation on VNC security.

In addition, the VNC password is saved in plain text in the configuration of the VM, so for the password to be effective, the user must not be able to display the VM configuration.

Procedure

  1. Open the configuration of the VM that you want to assign a VNC password to.
    # virsh edit <vm_name>
  2. On the <graphics> line of the configuration, add the passwd attribute and the password string. The password must be 8 characters or fewer.
     <graphics type='vnc' ports='-1' autoport='yes' listen='127.0.0.1' passwd='<password>'>
    • Optional: In addition, define a date and time when the password will expire.
       <graphics type='vnc' ports='-1' autoport='yes' listen='127.0.0.1' passwd='<password>' passwdValidTo='2025-02-01T15:30:00'>

      In this example, the password will expire on February 1st 2025, at 15:30 UTC.

  3. Save the configuration.

Results

  1. Start the modified VM.
    # virsh start <vm_name>
  2. Open a graphical console of the VM, for example by using the virt-viewer utility:
    # virt-viewer <vm-name>

    If the VNC password has been configured properly, a dialog window is displayed that requests you to enter the password.