136d7b
# The vncserver service unit file
136d7b
#
136d7b
# Quick HowTo:
288618
# 1. Copy this file to /etc/systemd/system/vncserver@.service
418d68
# 2. Replace <USER> with the actual user name and edit vncserver
11fd40
#    parameters in the wrapper script located in /usr/bin/vncserver_wrapper
136d7b
# 3. Run `systemctl daemon-reload`
136d7b
# 4. Run `systemctl enable vncserver@:<display>.service`
136d7b
#
136d7b
# DO NOT RUN THIS SERVICE if your local area network is
136d7b
# untrusted!  For a secure way of using VNC, you should
136d7b
# limit connections to the local host and then tunnel from
136d7b
# the machine you want to view VNC on (host A) to the machine
136d7b
# whose VNC output you want to view (host B)
136d7b
#
136d7b
# [user@hostA ~]$ ssh -v -C -L 590N:localhost:590M hostB
136d7b
#
136d7b
# this will open a connection on port 590N of your hostA to hostB's port 590M
136d7b
# (in fact, it ssh-connects to hostB and then connects to localhost (on hostB).
136d7b
# See the ssh man page for details on port forwarding)
136d7b
#
136d7b
# You can then point a VNC client on hostA at vncdisplay N of localhost and with
136d7b
# the help of ssh, you end up seeing what hostB makes available on port 590M
136d7b
#
136d7b
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
136d7b
#
136d7b
# Use "-localhost" to prevent remote VNC clients connecting except when
136d7b
# doing so through a secure tunnel.  See the "-via" option in the
136d7b
# `man vncviewer' manual page.
136d7b
136d7b
136d7b
[Unit]
136d7b
Description=Remote desktop service (VNC)
136d7b
After=syslog.target network.target
136d7b
136d7b
[Service]
11fd40
Type=simple
418d68
136d7b
# Clean any existing files in /tmp/.X11-unix environment
92eb38
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
11fd40
ExecStart=/usr/bin/vncserver_wrapper <USER> %i
92eb38
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
136d7b
136d7b
[Install]
136d7b
WantedBy=multi-user.target