Skip to content

Instantly share code, notes, and snippets.

@tavinus
Last active March 29, 2018 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tavinus/dc98f9a34f24efa8c34717a925e4fcc2 to your computer and use it in GitHub Desktop.
Save tavinus/dc98f9a34f24efa8c34717a925e4fcc2 to your computer and use it in GitHub Desktop.
Starts VNC server for the current session
#!/bin/bash
###########################################################################
# /usr/local/bin/x11vnc-start
# Starts VNC server for the current session
#
# Gustavo Neves - 4th Jul 2016
#
# Install x11vnc:
# sudo apt-get install x11vnc
#
# Install this script:
# sudo wget -q https://gist.githubusercontent.com/tavinus/dc98f9a34f24efa8c34717a925e4fcc2/raw/ -O /usr/local/bin/x11vnc-start && sudo chmod +x /usr/local/bin/x11vnc-start
#
# Setup:
# mkdir -p ~/.vnc && touch ~/.vnc/passwd
# x11vnc -storepasswd "YOUR_PASSWORD_HERE" ~/.vnc/passwd
#
# Run on boot:
# Look for Configuration >> Session and Initialization (or some like it)
# Add a new entry under Automatic Initializaion with the command:
# /usr/local/bin/x11vnc-start &>/dev/null &
#
###########################################################################
vnc_bin="$(which x11vnc)"
vnc_port="5900" # Change port here
vnc_auth_path="$HOME/.vnc" # Change auth path here
vnc_auth_file="$vnc_auth_path/passwd" # Change auth file here
if [[ -z $vnc_bin ]]; then
echo "Could not find x11vnc executable, aborting.."
echo "Maybe you want to:"
echo " sudo apt-get install x11vnc"
exit 1
elif [[ ! -f $vnc_auth_file ]]; then
echo "There is no passwd file."
echo "Please run:"
echo " mkdir -p $vnc_auth_path && touch $vnc_auth_file"
echo " x11vnc -storepasswd "'"YOUR_PASSWORD_HERE"'" $vnc_auth_file"
exit 2
else
"$vnc_bin" -auth guess -forever -loop -noxdamage -repeat -rfbauth "$vnc_auth_file" -rfbport "$vnc_port" -shared &>/dev/null &
exit 0
fi
exit 9 # should never get here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment