136d7b
# The vncserver service unit file
136d7b
#
136d7b
# Quick HowTo:
288618
# 1. Copy this file to /etc/systemd/system/vncserver@.service
2bf600
# 2. Edit /etc/systemd/system/vncserver@.service, replacing <USER>
2bf600
#    with the actual user name. Leave the remaining lines of the file unmodified
2bf600
#    (ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
2bf600
#     PIDFile=/home/<USER>/.vnc/%H%i.pid)
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]
8b1cd8
Type=forking
136d7b
# Clean any existing files in /tmp/.X11-unix environment
136d7b
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
288618
ExecStart=/usr/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
8b1cd8
PIDFile=/home/<USER>/.vnc/%H%i.pid
8b1cd8
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
136d7b
136d7b
[Install]
136d7b
WantedBy=multi-user.target