2

OS: GNU/Linux Debian 9 with Cinnamon DE.

Since we managed to get VNC on Debian server running, thanks to GAD3R again, it's time to make VNC a regular service.

I want it to be running all the time, since boot, without having to SSH to server, while running:

x11vnc -rfbauth ~/.vnc/passwd

Also, I don't want to run a separate Cinnamon session, I want to see directly what's on the primary screen or whatever you call it, and manipulate with that session live.

Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309
  • Do be aware though, that passwords stored in vnc password files are limited to [8 characters](http://forum.ultravnc.info/viewtopic.php?f=4&t=15459) and [trivially decryptable](https://github.com/jeroennijhof/vncpwd) and really shouldn't be used. See my question: [Secure way to allow sharing an Xubuntu / XFCE dektop remotely?](https://askubuntu.com/questions/1211445/secure-way-to-allow-sharing-an-xubuntu-xfce-dektop-remotely) – Peter V. Mørch Feb 18 '20 at 22:49
  • @PeterV.Mørch I noticed that. Actually I gave up on using VNC, as it's slow with any setting I have tried. – Vlastimil Burián Feb 18 '20 at 23:35

2 Answers2

10

Similar to Vlastimil's own solution, but with a few other details: (from VNC server for Cinnamon with systemd)

Create the file /etc/systemd/system/x11vnc.service :

[Unit]
Description=VNC Server for X11
Requires=display-manager.service
After=syslog.target network-online.target ##optional for better performance
Wants=syslog.target network-online.target ##optional for better performance

[Service]
ExecStart=/usr/bin/x11vnc -display :0 -rfbauth /etc/x11vnc.pwd -shared -forever -o /var/log/x11vnc.log
ExecStop=/usr/bin/x11vnc -R stop
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

Generate and Set the VNC password (replace MY_PASSWORD)

x11vnc -storepasswd MY_PASSWORD /etc/x11vnc.pwd

Finally:

systemctl daemon-reload
systemctl enable x11vnc
systemctl start x11vnc
Ingo Mi
  • 232
  • 1
  • 7
mivk
  • 3,446
  • 29
  • 31
  • technically your `ExecStop` doesn't work, also, when you stop the service, it works exactly the same if you remove this parameter note: it does show an error, either way so I just removed `ExecStop` – Jared Oct 31 '22 at 17:41
3

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.

Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309