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