noVNC with x11vnc

Thursday March 22, 2018

This entry is going to be really brief. So I tried using VirtualBox’s Seamless Mode (host: Windows 10; VM: Xubuntu 17:10) but the Seamless Mode was so damn awkward. Then I was reminded of noVNC, a VNC client that lives on the web browser communicating through WebSocket protocol.

Long story cut short, I downloaded noVNC to serve x11vnc, then autostarted both with systemd unit files. The strategy worked beautifully. Now every time I start my Xubuntu VM, I run it in detached mode so I can close the GUI and use the noVNC as the GUI.

I installed x11vnc through apt. Then I cloned noVNC’s git repository to ~/Documents.

git clone https://github.com/novnc/noVNC

The noVNC is now available in ~/Documents/noVNC.

This is the systemd unit file for the noVNC, located at the /etc/systemd/system/novnc.service.

[Unit]
Description = start noVNC service
After=syslog.target network.target

[Service]
Type=simple
User=arya
ExecStart = /home/arya/Documents/noVNC/utils/launch.sh 

[Install]
WantedBy=multi-user.target

This systemd unit file runs launch.sh under the user arya. Change it to your $USER.

This is the systemd unit file for x11vnc, located at /etc/systemd/system/x11vnc.service.

[Unit]
Description="x11vnc"
Requires=display-manager.service
After=display-manager.service

[Service]
ExecStart=/usr/bin/x11vnc -xkb -noxrecord -noxfixes -noxdamage -display :0 -auth guess -rfbauth /etc/x11vnc.pass
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure
Restart-sec=2

[Install]
WantedBy=multi-user.target

This systemd unit file requires x11vnc to run with a password. Generate password by running this command:

sudo x11vnc -storepasswd YOURPASSWORD /etc/x11vnc.pass

To run:

# x11vnc
sudo systemctl start x11vnc

# noVNC
sudo systemctl start novnc

To enable both at start-up:

# For x11vnc
sudo systemctl enable x11vnc

# For noVNC
sudo systemctl enable novnc

The noVNC instance should be accessible at :6080. My Xubuntu VM’s hostname is hendriks, so my noVNC instance is accessible at hendriks:6080. Neat!

To kill noVNC, run sudo netstat -plunt and find the process ID (PID) that is associated with port 6080. Most likely you will see it being a python application. Then, kill the process by passing kill -9 {PID}.