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