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