Created
March 7, 2021 22:42
-
-
Save hadi77ir/a3287bc5b4588e5b125a66dd9df1c805 to your computer and use it in GitHub Desktop.
Run x0vncserver with
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 $* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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