The problem: Raspberry connected to a TV / share the desktop
When connecting a RapsberryPi to a screen or TV to show something you surely would like to remote control the RasPi not only via shell (SSH) but also via VNC to see exactly what is displayed on the remote screen. So what we are looking for is not “a new remote desktop” (as provided by a lot of tools) but “desktop sharing”. And of course you want the desktop shared automatically when the Raspberry Pi boots.
Yet thanks to the great and large Rapsberry Pi community, this is a pretty easy task – if you know how to do it …
Solution: x11vnc
Use raspi-config
to configure the raspi to “Enable Boot to Desktop”.
Install x11vnc:
sudo apt-get install x11vnc
Configure x11vnc to set a password automatically when it is started:
sudo x11nvc -storepasswd
Create a file /etc/init.d/x11vnc
which is used on startup (mind the line breaks! Or just get it from GitHub). And set the permissions to 755 (sudo chmod 755 /etc/init.d/x11vnc
).
#!/bin/sh # /etc/init.d/x11vnc ### BEGIN INIT INFO # Provides: x11vnc # Required-Start: lightdm # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: x11vnc # Description: ### END INIT INFO case "$1" in start) echo "Starting x11vnc ... " x11vnc -auth /var/run/lightdm/root/:0 -rfbauth /root/.vnc/passwd -no6 -noipv6 -reopen -forever -shared ;; stop) echo "Killing x11vnc ..." killall x11vnc ;; *) echo "Usage: /etc/init.d/x11vnc {start|stop}" exit 1 ;; esac exit 0
You could now test the script already via:
sudo service x11vnc start
Tell the RasPi to start x11vnc automatically after the graphical environment has started:
sudo update-rc.d x11vnc defaults
Done. Reboot your RasPi to test if everything did work. When it has come up again, you should be able to connect to the desktop from your Linux/Mac/Windows machine with a VNC client of your choice, for example TightVNC. Simply enter the host name of the Raspi in the connect dialogue and hit ok. That’s it.
Thx Franz,
this is the HowTo i was looking for last Year to use an Raspberry Pi as an Process Display for a B&R PLC running a VNC based Visualization. I also built a working
Solution but i didn’t get the job so i dropped the Development on the Raspberry Pi. Your HowTo is a reminder to consider this Solution again in future projects.
Regards Michi
(Sorry for my English, Bavarian’s my prefered Language