I wanted to set up VNC on my Raspberry Pi so I could use it via a remote desktop on my MacBook Air. There are lots of instructions scattered in various places around the web, but now I've put together a comprehensive set of things to do, I thought it might be useful to share it in one place.
[Source: Getting Started With Raspberry Pi]
On the Pi:
sudo apt-get install netatalk
Now from the Mac, open Finder, and hit ⌘K. Enter afp://192.168.0.22 (using the IP address of your Pi).
On the Pi:
sudo apt-get install avahi-daemon sudo update-rc.d avahi-daemon defaults
Now create a file /etc/avahi/services/afpd.service (as root):
sudo vim /etc/avahi/services/afpd.service
and add this content:
<?xml version="1.0" standalone='no'?><!--*-nxml-*--> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_afpovertcp._tcp</type> <port>548</port> </service> </service-group>
Then run this command:
sudo /etc/init.d/avahi-daemon restart
You should now be able to see the Pi in the Finder sidebar.
[Source: Raspberry Pi forum]
On the Pi:
sudo apt-get install tightvncserver vncserver
Enter an eight character password.
Now do:
cd /etc/init.d sudo vim tightvncserver
Add the following content to the file:
#!/bin/bash # /etc/init.d/tightvncserver # # Carry out specific functions when asked to by the system case "$1" in start) su pi -c '/usr/bin/vncserver -geometry 1440x900' echo "Starting VNC server " ;; stop) pkill vncserver echo "VNC Server has been stopped (didn't double check though)" ;; *) echo "Usage: /etc/init.d/blah {start|stop}" exit 1 ;; esac exit 0
(Change the geometry setting if your monitor is a different size.)
Now do:
sudo chmod +x tightvncserver sudo pkill Xtightvnc
Check the VNC server is not running:
ps aux | grep vnc
Then do:
sudo /etc/init.d/tightvncserver start cd /etc/init.d sudo update-rc.d tightvncserver defaults
[Source: Getting Started With Raspberry Pi]
Create the avahi rfb service file:
sudo vim /etc/avahi/services/rfb.service
and add this content:
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_rfb._tcp</type> <port>5901</port> </service> </service-group>
Then run:
sudo /etc/init.d/avahi-daemon restart
Now you should be able to see the Screen Share option for the Pi in your Finder sidebar.
If you're also running an X session directly on the Pi (i.e. not through VNC), consider disabling the screensaver. You might forget that this X session is running if you're not looking at the monitor (or if the monitor is turned off), and you'll wonder what's eating all the CPU suddenly after ten minutes. (Yes, this happened to me!)
This work is licensed under
a Creative Commons Attribution-ShareAlike 4.0
International License.