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