1. Using SSH or temporary monitor, login to your pi.
2. Install X11VNC:
sudo apt-get update
sudo apt-get install x11vnc
3. Set connection password. This will be prompted when a client computer is establishing connection.
x11vnc -storepasswd
4. Auto-run x11vnc. Edit xsessionrc:
sudo nano ~/.xsessionrc
Find this line and edit it:
Start X11VNC x11vnc -bg -nevershared -forever -tightfilexfer -usepw -display :0
This will run vnc service on port 5900 when desktop is loaded. Save the file
5. Give the file execute permission:
sudo chmod 777 ~/.xsessionrc
6. The program wont know your client’s monitor resolution. It shows a small window by default. To adjust this, find the right HDMI code and edit the boot config file
sudo nano /boot/config.txt
Enable HDMI. Find this line and uncomment it:
hdmi_force_hotplug=1
Find the setting that match your computer display from here: https://www.raspberrypi.org/documentation/configuration/config-txt.md
7. Restart your Pi
8. x11vnc will start as soon as the desktop gui is start. You can set your pi to start desktop environment from raspi-config.
Or you can manually start it via SSH by calling: startx
9. For the client side, once your got x11vnc running on the pi, you can use TightVNC or Remmina to log into the pi. For example:
vncviewer yourpiidaddress:0
Enter the password your set up initially when prompted.
If in some cases, startx won’t load desktop environment quoting “connectioned refused”, there could be permission issue with your /tmp folder.
sudo chmod ug+rwx,o+rwt /tmp
Reference
http://blog.tonywall.co/2013/07/setting-up-raspberry-pi-for-headless-mode-with-x11vnc/
https://melgrubb.wordpress.com/2014/08/01/raspberry-pi-home-server-part-5-remote-desktop/
http://www.thefruitycomputer.com/forums/tutorials/article/24-autostart-x11vnc-in-raspbian/