Skip to content

Instantly share code, notes, and snippets.

@vpalmisano
Forked from spinxz/vncserver@:1.service
Created March 17, 2023 15:06
Show Gist options
  • Save vpalmisano/2a62d5c0d2bd6bf67f65ae65847dcf17 to your computer and use it in GitHub Desktop.
Save vpalmisano/2a62d5c0d2bd6bf67f65ae65847dcf17 to your computer and use it in GitHub Desktop.
systemd service file for running a vncserver (e.g. tightvncserver)
# Vncserver service file for Debian or Ubuntu with systemd
#
# Install vncserver and tools
# e.g. apt-get install tightvncserver autocutsel gksu
#
# 1. Copy this file to /etc/systemd/system/vncserver@:1.service
# 2. Edit User=
# e.g "User=paul"
# 3. Edit the vncserver parameters appropriately in the ExecStart= line!
# e.g. the -localhost option only allows connections from localhost (or via ssh tunnels)
# 4. Run `systemctl daemon-reload`
# 5. Run `systemctl enable vncserver@:<display>.service`
#
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=<user_name>
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver -geometry 1800x1000 -depth 16 -dpi 120 -alwaysshared -localhost %i
ExecStop=/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target
#!/bin/sh
# vnc server xstartup file (~/.vnc/xstartup) for LXDE
#
# The sleeps seem to fix a bug where user input is not registered in vncviewer on client
#
# Fix to make GNOME work:
export XKL_XMODMAP_DISABLE=1
# hack to allow sudo in vncviewer:
xhost +localhost
autocutsel -fork
sleep 2
# unclear if the x-window-manager is needed:
x-window-manager &
sleep 2
lxterminal &
sleep 2
/usr/bin/lxsession -s LXDE -e LXDE &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment