I recommend using
x11vnc, write a simple script and execute it in
Difference between x11vnc and traditional Unix VNC.
x11vnc interacts directly with physical displays
A sample shell script
x11vnc -safer -forever -display :0 -rfbauth ~/.vnc/passwd >/tmp/x11vnc.log 2>&1 &
Below I have included the install/config details I wrote for another question: VNC on UBUNTU 13.04 - not showing full desktop
sudo apt-get install x11vnc
Create VNC password
NOTE: defaults to
~/.vnc/passwd file. Alternatively, use
-storepasswd pass file
Store password pass as the VNC password in the file file. Once the password is stored the program exits. Use the password via "
-rfbauth file". If called with no arguments, "
x11vnc -storepasswd", the user is prompted for a password and it is stored in the file ~/.vnc/passwd. Called with one argument, that will be the file to store the prompted password in.
# Start x11vnc using ~/.vnc/passwd
x11vnc -safer -forever -display :0 -rfbauth /home/terry/.vnc/passwd
# less output to stderr -q -quiet
# this does not eliminate all informational output, it only reduces it
x11vnc -safer -forever -display :0 -rfbauth /home/terry/.vnc/passwd -q
# eliminate all output
x11vnc -safer -forever -display :0 -rfbauth /home/terry/.vnc/passwd 2>/dev/null 1>2&
Change the VNC port to listen on
The VNC port to listen on (a LibVNCServer option), e.g. 5900, 5901, etc. If specified as "-rfbport PROMPT" then the x11vnc -gui is used to prompt the user to enter the port number.
x11vnc -rfbport 5901
This force x11vnc to use port 5901 (this is VNC display :1.)
If something else is using that port x11vnc will exit immediately. If you do not supply the
-rfbport option, it will autoprobe starting at 5900 and work its way up to 5999 looking for a free port to listen on.
Send x11vnc to background
x11vnc -safer -forever -display :0 -rfbauth /home/terry/.vnc/passwd -bg
Go into the background after screen setup. Messages to stderr are lost unless -o logfile is used.
VNC password file
-rfbauth .vnc/passwd provides additional protection by requiring a VNC password for every VNC viewer that connects. The
storepasswd programs, or the
x11vnc -storepasswd option can be used to create the password file.
x11vnc also has the slightly less secure
-passwd XXXXX options to specify passwords.