Skip to content

Instantly share code, notes, and snippets.

@hadi77ir
Created March 7, 2021 22:42
Show Gist options
  • Select an option

  • Save hadi77ir/a3287bc5b4588e5b125a66dd9df1c805 to your computer and use it in GitHub Desktop.

Select an option

Save hadi77ir/a3287bc5b4588e5b125a66dd9df1c805 to your computer and use it in GitHub Desktop.
Run x0vncserver with
#!/bin/bash
die() { echo "error: $@"; exit 1; }
(( EUID == 0 )) || die 'this must be run as root';
if [[ "$DISPLAY" == "" ]] ; then
# set display to :0
export DISPLAY=":0"
fi
if [[ "$XAUTHORITY" == "" ]] ; then
# try finding it out through Xorg arguments
export XAUTHORITY=$(pgrep -a Xorg | awk -F' ' '{ for(i = 1; i<=NF; i++) { if($i == "-auth") { i++; print $i; } } }')
fi
export NEW_XAUTHORITY=/var/run/x0vncserver/.Xauthority
mkdir -p $(dirname $NEW_XAUTHORITY)
# export xauthority
xauth extract "$NEW_XAUTHORITY" "$DISPLAY"
# allow local x connections
xhost +local:
XAUTHORITY=$NEW_XAUTHORITY /usr/bin/x0vncserver $*
[Unit]
Description=Remote desktop service (VNC)
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
ExecStartPre=/bin/sh -c 'while ! pgrep Xorg; do sleep 2; done'
# login with your username & password
ExecStart=/usr/local/bin/x0vncserver-run -PAMService=login -PlainUsers=* -SecurityTypes=TLSPlain -AlwaysShared -DisconnectClients -display=:0 -UseIPv4 -rfbport=5000
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment