Setting up a Raspberry Pi with file sharing and screen sharing for Macs

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

  1. Download the raw Raspbian image from Raspberry Pi website.
  2. Use Mac’s Disk Utility to format the SD card into one FAT partition.
  3. 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)
  4. Plug the SD card into the Pi and boot up.
  5. Use the raspi-config tool that starts the first time you boot up to set the following options:
    1. Expand the root partition to fill the disk
    2. Enable SSH
    3. Start desktop on boot
    4. Change the hostname
    5. Change the default password
  6. Reboot the Pi, you should get into the desktop.
Raspbian Desktop Screen
The default Raspbian desktop screen

Setting up file sharing (AFP) and screen sharing (VNC)

  1. On the Raspberry Pi, open up LXTerminal.
  2. In LXTerminal, execute sudo apt-get install netatalk x11vnc to install the necessary packages. (You may need to execute sudo apt-get update to update the package list if it complains about missing packages.)
  3. Execute x11vnc -storepasswd to setup the password required for your screen sharing connections.
  4. 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
  5. 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.

  6. 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.
rpi-afp-vnc
Raspberry Pi file sharing and screen sharing from a Mac

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:

  1. Plug the SD card into the Mac.
  2. In Terminal, execute diskutil list to find your SD card make note of the disk number (/dev/diskX)
  3. 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).
  4. 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.

References

Related

29 thoughts on “Setting up a Raspberry Pi with file sharing and screen sharing for Macs

  1. 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.

    1. 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.

      1. 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!

  2. 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?

      1. 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.

        1. 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.

  3. 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.

    1. 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?

  4. 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?

    1. 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!!

  5. 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.

  6. 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

  7. 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!

  8. THANKS big time

    your instruction were great
    and the system works wonderfully

    now controlling multiple RPI 2
    from one mac osx10.10

    many thanks

  9. 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.

  10. 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

    1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.