55ccb6
# The vncserver service unit file
55ccb6
#
55ccb6
# Quick HowTo: As the User wanting to have this functionality
55ccb6
#
55ccb6
# 1. Copy this file to ~/.config/systemd/user/ (Optional, in case default settings are not suitable)
55ccb6
#
55ccb6
#   $ mkdir -p ~/.config/systemd/user
55ccb6
#   $ cp /usr/lib/systemd/user/vncserver@.service ~/.config/systemd/user/
55ccb6
#
55ccb6
# 2. Reload user's systemd
55ccb6
#
55ccb6
#    $ systemctl --user daemon-reload
55ccb6
#
55ccb6
# 3. Start the service immediately and enable it at boot
55ccb6
#
55ccb6
#    $ systemctl --user enable vncserver@:<display>.service --now
55ccb6
#
55ccb6
# 4. Enable lingering
55ccb6
#
55ccb6
#    $ loginctl enable-linger
55ccb6
#
55ccb6
# DO NOT RUN THIS SERVICE if your local area network is
55ccb6
# untrusted!  For a secure way of using VNC, you should
55ccb6
# limit connections to the local host and then tunnel from
55ccb6
# the machine you want to view VNC on (host A) to the machine
55ccb6
# whose VNC output you want to view (host B)
55ccb6
#
55ccb6
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
55ccb6
#
55ccb6
# this will open a connection on port 590N of your hostA to hostB's port 590M
55ccb6
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
55ccb6
# See the ssh man page for details on port forwarding)
55ccb6
#
55ccb6
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
55ccb6
# the help of ssh, you end up seeing what hostB makes available on port 590M
55ccb6
#
55ccb6
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
55ccb6
#
55ccb6
# Use "-localhost" to prevent remote VNC clients connecting except when
55ccb6
# doing so through a secure tunnel.  See the "-via" option in the
55ccb6
# `man vncviewer' manual page.
55ccb6
55ccb6
55ccb6
[Unit]
55ccb6
Description=Remote desktop service (VNC)
55ccb6
After=syslog.target network.target
55ccb6
55ccb6
[Service]
55ccb6
Type=forking
55ccb6
55ccb6
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
55ccb6
ExecStart=/usr/bin/vncserver %i
55ccb6
ExecStop=/usr/bin/vncserver -kill %i
55ccb6
55ccb6
Restart=on-success
55ccb6
RestartSec=15
55ccb6
55ccb6
[Install]
55ccb6
WantedBy=default.target