First, it might be a good idea to copy the password file under /etc/
, something like:
sudo cp ~/.vnc/passwd /etc/vnc.passwd
This also ensures the ownership to root
and his rw
access, as confirmed by:
$ ll /etc/vnc.passwd
-rw------- 1 root root 8 Nov 3 04:00 /etc/vnc.passwd
Second, we have to create the service file ourselves:
sudo nano /lib/systemd/system/vnc.service
while the simplest solution I came up with is for it to contain:
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/vnc.passwd -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target
Note, while it is by far the simplest service file, it can't even have support for stop or restart, I myself need to figure this out yet.
Disclaimer: The man page is quite lengthy, and maybe I've made some serious, e.g. security mistake here. Use on your own risk.
sudo systemctl enable vnc.service
sudo systemctl daemon-reload
and you may simply reboot the machine.
As a side-note, on the client-side, you may want to copy the password file from the server for you not to enter a password each time, you connect, and define some alias similar to:
alias vnc-server='(vncviewer 192.168.0.xxx:5900 -passwd /home/UserName/.vnc/server.passwd > /dev/null 2>&1 &)'
so that it won't flood your terminal.