Start VNC together with LightDM

If you want to start a VNC server before login on your Linux machine a good option is to make the graphical login manager start the VNC server, in my case LightDM.

This solution will restart the VNC server if you logout since the VNC server will exit on logout.

Add the following to /etc/lightdm/lightdm.conf

display-setup-script = /etc/lightdm/display-setup-script.sh

And create the file /etc/lightdm/display-setup-script.sh and add the line to start your VNC server in that file

#!/bin/bash
/usr/bin/x11vnc -xkb -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc/passwd \
-forever -bg -gone "xscreensaver-command -lock" -nodpms -rfbport 5900 -httpdir /usr/share/vnc-java/ -httpport 5800 \
-rfbversion 3.6 -permitfiletransfer -shared -dontdisconnect -alwaysshared -o /var/log/x11vnc.log &

Make the script executable

sudo chmod u+x display-setup-script.sh

Restart Lightdm

service lightdm restart

Start VNC together with LightDM | Roger Steneteg.