I’m going to briefly explain how to setup a new Raspberry Pi as a basic desktop computer with file sharing and screen sharing so that Macs can connect to it. This will be useful for quickly transferring files over, and taking control of the Pi remotely. I will be assuming that you have basic command line knowledge (running commands, installing packages, editing text files), and some Mac knowledge. I am not going to be too paranoid about security as I only intend on using my Pi on my home network, but if your Pi is going to be Internet-facing, you may want to read up elsewhere on securing your Pi.
Installing the Raspbian image onto the SD card
- Download the raw Raspbian image from Raspberry Pi website.
- Use Mac’s Disk Utility to format the SD card into one FAT partition.
- Download RPi-sd card builder. Use it to load the Raspbian image onto the SD card. (It will take a while… don’t take the SD card out until you get the final prompt and the cogwheel stops spinning in the menu bar)
- Plug the SD card into the Pi and boot up.
- Use the raspi-config tool that starts the first time you boot up to set the following options:
- Expand the root partition to fill the disk
- Enable SSH
- Start desktop on boot
- Change the hostname
- Change the default password
- Reboot the Pi, you should get into the desktop.
Setting up file sharing (AFP) and screen sharing (VNC)
- On the Raspberry Pi, open up LXTerminal.
- In LXTerminal, execute
sudo apt-get install netatalk x11vnc
to install the necessary packages. (You may need to executesudo apt-get update
to update the package list if it complains about missing packages.) - Execute
x11vnc -storepasswd
to setup the password required for your screen sharing connections. - In order for the VNC server to start up at each boot, create the following file in
~/.config/autostart/x11vnc.desktop
[Desktop Entry] Encoding=UTF-8 Type=Application Name=X11VNC Comment= Exec=x11vnc -forever -usepw -display :0 -ultrafilexfer StartupNotify=false Terminal=false Hidden=false
- To register the VNC server as a Bonjour service, create the following file in
/etc/avahi/services/rfb.service
(you will need to save the file as root, so use sudo before opening your editor).<?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>5900</port> </service> </service-group>
If you don’t see an /etc/avahi folder, you may need to install the avahi package separately — recent netatalk packages will install avahi as a dependency, so if you’re doing a new install it shouldn’t be a problem.
- Reboot. You should then be able to go into Finder and find your Raspberry Pi on the network. File sharing and screen sharing should be accessible as well.
Backing up
After doing some customization of the Raspberry Pi, you may want to take a backup of it so that in case the SD card gets corrupted, you can easily restore the image. I found an excellent guide on this blog post. Summarizing it quickly:
- Plug the SD card into the Mac.
- In Terminal, execute
diskutil list
to find your SD card make note of the disk number (/dev/diskX) - Then execute the following command for a backup:
sudo dd if=/dev/rdiskX bs=1m | gzip > /path/to/backup.img.gz
Replace the X with your disk number that you found in the previous step. Note the ‘r’ in/dev/rdiskX
is intentional to take advantage of better performance (see the blog post I linked for details). - For a restore, the command would be:
gzip -dc /path/to/backup.img.gz | sudo dd of=/dev/rdiskX bs=1m
That’s it! This was a quick overview of getting a Raspberry Pi setup and talking with Macs for easy file transfers and remote control, and also backed up in case something bad happens.
Thank you for this tutorial for x11vnc
The issue I am having is that when I press share screen on by mac, there is an error message that says:
Connection failed to “raspberrypi”.
Please make sure that Screen Sharing (in the Sharing section of System Preferences) is enabled on the computer to which you are attempting to connect. Also make sure your network connection is working properly.
Could you help, possibly? Thanks.
Check if x11vnc is running. I don’t have a Pi with me right now, but you should be able to run:
ps ax | grep x11vnc
And there should be a line with the x11vnc process (other than the grep).
If you don’t see a line for x11vnc, it didn’t start properly. Check your autostart script and try executing it directly from a terminal console to see if there are any errors:
x11vnc -forever -usepw -display :0 -ultrafilexfer
Those are the things I can think of off the top of my head right now, I don’t have a Pi with me to debug this. Let me know how it goes.
this was really helpful, thanks!
I reckon i needed to reboot twice? I followed the instructions, and could not connect from the mac, then ran the command via ssh, saw errors, rebooted, bingo!
Not sure about that, but if a reboot helps then great 🙂 Glad it’s working for you.
Hi Dennis,
thanks a lot for your tutorial. Everything is working fine, when i have the Raspberry connected to my TV screen vie HDMI. But as soon as I try to start and access the Raspbi without HDMI/TV I can not get any access to the raspy. SSH does not work, and Ihave no access to the Raspi using my Macs Finder.
It’s strange!! Can you help?
Sorry, I don’t really know. Are you able to ping it to see if it booted up?
Hi,
it was a problem with my Ethernet connection. Your scripts
ar working perfect! Thank’s a lot.
Another question: How can I change the raspbi’s window size on my MacBook?
All the best, tone.
Sorry about the delayed reply. You’d probably need to adjust the resolution on the pi. If you’re using RCA video out, I don’t think you can increase the resolution though. Not sure about HDMI.
This works great, thank you very much!!
The one problem I’ve had is that the resolution is very low… any ideas on how to change this? When I use tightvnc and Chicken, resolution is much higher / normal but more painful to access each time.
Unfortunately I can only speak of my experiences using RCA video out on my Pi, and since VNC just mirrors that output, the VNC feed has the same low resolution which I expect. What video output are you using on your Pi?
In /boot/config.txt I uncommented the framebuffer width and height variables and rebooted.
DUMB question, but I made the file in the .config myself and am wondering if it needs to be executable and what other permissions it needs?
Even dumber, I had to make the autostart folder as well, as it too was missing…. do I need to get permissions on it right too, and am needing to chown these to root? Or may they remain owned by pi…. I am not certain that the VNC service is running at all?
I made the file by doing a touch foo , then adding your text using vi, saving it, using mv to change the name…. Am I screwing this all up? Sorry if I am!!
Sorry to reply so late, but I believe they can be owned by pi as the startup items are done at the user level if I recall correctly.
thanks mate. it works perfect (after rebooting the pi)
:0)
Thanks for this. It worked perfectly.
Thanks again. I do not understand the backup portion. I do not understand how to make the image of the Pi on the Mac, so that the /path/to/backup.img.gz can be populated. My apologies if this step is obvious to others.
If you want more details about the backup and restore process, please take a look at this page that I linked in the post.
The /path/to/ part can be any folder on your computer.
I just got a B+ and have established an SSH connection with my Macbook. I would like to have a GUI connection.
Your tutorial implies that you have a keyboard and screen attached to the Pi. I only have my Macbook. Will I be able to use your tutorial with this configuartion?
Thanks
If you can connect to your Pi over SSH, you should be able to execute the same commands to setup file and screen sharing over SSH.
Hi Dennis!
This worked great, thank you so much.
One question if you don’t mind: how can i set up the Pi to display a screen size larger than 656×416?
Thanks again!
oops, I just read the rest of the comments. sorry!
THANKS big time
your instruction were great
and the system works wonderfully
now controlling multiple RPI 2
from one mac osx10.10
many thanks
Thanks again for these instructions. As of July 2015, it seems that the step to manually create the
rfb.service
file is unnecessary. In fact, when I did that, I did not see my Pi across the network. So, you need to still install the netatalk and x11vnc packages, and set up the x11vnc configuration, but no need to create the rfb.service file manually.Worked without a hitch.Thanks a lot!
hey, i am ssh-ing into a rpi 2 and i dont understand which folder/directory this “~/.config/autostart/x11vnc.desktop” is. how do i get there to create the file? Thanks, Jakob
The “~” is a shorthand for the user’s home directory. So when you first ssh in your “current directory” will be “~” – you can see the translation by executing pwd. With the default “pi” account this will print: /home/pi.
Regardless of your current directory you can create the desired directory with the command: mkdir -p ~/.config/autostart/
Then create and edit the file: nano ~/.config/autostart/x11vnc.desktop
Appreciate it for this post, I am a big big fan of this website would like to proceed updated.