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