In this Raspberry Pi Apple Filing Protocol tutorial, we will show you how you can share directories on your Pi using the Apple Filing Protocol (AFP).

Raspberry Pi AFP
The Apple Filing Protocol is Apple’s proprietary network protocol for delivering files over a network. It is Apple’s alternative to the Server Message Block (SMB) and Network File System (NFS) protocols.

By following this tutorial, you will be able to share any directories on your Raspberry Pi using AFP and easily connect to them from a device running the Mac OS X operating system.

All of this is made possible by the “Netatalk” software. This software implements the “AFP” protocol at a server level allowing your Raspberry Pi to serve files over it.

There are plenty of other NAS solutions that you can take advantage of so if this doesn’t take your fancy I highly suggest taking a look at them.

Equipment

Below is all the equipment that you will need for setting up the Apple Filing Protocol on your Raspberry Pi.

Recommended

Raspberry Pi

Micro SD Card (8GB+) if you’re using a Raspberry Pi 2, 3 or B+

Ethernet Cord or Wifi dongle

External Hard drive

Optional

Raspberry Pi Case

USB Keyboard

USB Mouse

Note: The USB ports on the Raspberry Pi might not be enough to power an external drive so you might need to invest in a powered USB hub.

Setting up Apple File Protocol (AFP) On your Raspberry Pi

1. Now before we can setup the Apple File Protocol (AFP) on your Raspberry Pi, we must first ensure that the operating system is up to date.

To ensure everything is up to date run the two commands below.

sudo apt update
sudo apt upgrade

2. With the Raspberry Pi now up to date, we can now proceed to install the package that will be handling everything.

The package that we are installing is called Netatalk. Netatalk is a free and open source implementation of the Apple Filing Protocol (AFP).

The Netatalk program acts as a file server that is capable of serving many Mac clients as it allows your Raspberry Pi to act as an AppleShare file server.

Install the Netatalk application to your Raspberry Pi by running the following command.

sudo apt install netatalk

3. As we have now installed the netatalk software, we will now have to go ahead and configure it to share different directories.

We will explain how to make a connection to thedr AFP share in our next section but for now, let’s look into adding directories to be shared.

To do this, we must modify the “afp.conf” file by running the command below.

sudo nano /etc/netatalk/afp.conf

4. Within this file add the following text to the bottom of the file.

Adding Home Directories

[Homes]
  basedir regex = /home

This block defines our home directories. This block will allow any connecting user to access their respective home folders.

We define the “basedir regex” so that the Netatalk software knows where to look for the users home directory.

If you would like to lock the user to a specific directory within their home path, you can add the following option. With <foldername> being the name of that directory.

[Homes]
  basedir regex = /home 
  path = <foldername>

Adding Custom Directories

[My AFP Share Name]
  path = /path/to/directory

Using something like above we can share any directory that we want.

Within the square brackets ([ ]) that designate the start of the share is the name given to said share.

The “path=” option is the path to the directory that you want to share over the AFP protocol.

Making a share an Apple Time Machine share

[My AFP Share Name]
  path = /path/to/directory
  time machine = true

You can specify any share as a time machine capable share by simply adding the option “time machine = true” under it.

Making a share read only

[My AFP Share Name]
  path = /path/to/directory
  read only = true

If you would like to make a share read-only, all you have to do is add “read only = true” to it. This option is useful for shares, such as sharing a media library.

Setting the guest account

[Global]
  guest account = pi

You can specify a guest account to utilize for connections by setting “guest account =” under the “[Global]” header. By default, this is set to “nobody“.

You can find more information about the options that you can specify by going to NetaTalk’s configuration documentation.

5. With changes to the configuration complete, you can go ahead and save the file by pressing CTRL + X then Y followed by ENTER.

6. As we have made changes to Netatalk’s configuration, we need to restart the service so that it can utilize the new config.

We can restart the service by running the following command.

sudo systemctl restart netatalk

7. Before we connect to our newly shared folders, we should retrieve the IP address assigned to our Raspberry Pi.

Make sure you have an active network connection by using either WiFi or an Ethernet cable.

Write this IP down as we will need it for connecting to the shared drive.

sudo hostname -I

Connecting to your Pi’s AFP share on MAC OS X

1. To connect to your Raspberry Pi’s AFP share begin by opening the “Finder” application available on the Mac OS X operating system.

Opening Finder on Mac OS X

2. Now that we have opened up the “Finder” application go ahead and click “Go” (1.) in the toolbar at the top of the screen. Next, click the “Connect to Server…” (2.) option.

Mac OS X Connect to AFP protocol

3. Within this dialog, you will need to enter your Raspberry Pi’s IP address in front of the “afp://” protocol (1.).

For example, with our Raspberry Pi’s IP address being “192.168.0.159” we need to enter “afp://192.168.0.159” into the input box.

Once entered, click the “Connect” button (2.) to proceed.

Mac OS X Enter Raspberry Pi AFP Details

4. Upon connecting to your Raspberry Pi, you will be greeted by a dialog asking you to enter a username and password to connect to the Apple Filing Protocol server (1.).

As we are just using the default user, we only used “pi” as the name and “raspberry” as the password.

Once you have entered a user to connect with, go ahead and click the “Connect” button (2.) to proceed.

Mac OS X Enter AFP Share Login Details

5. Upon successfully logging into your Raspberry Pi’s AFP share you will now be asked what volumes that you want to mount.

This dialog will show all directories that you set up earlier in the tutorial, each referenced by the name you put next to that share in the config file.

Select the volumes that you want to be mounted (1.) Then click the “Ok” button to proceed.

Raspberry Pi AFP - Step 05 - Select Drives

6. Finally, you will now be able to see the shares that you mounted to your Mac OS X device.

Below we have included a screenshot showing the networked drives under “Locations” in the sidebar. We also show the shared volumes that are within the “Finder” application.

Raspberry Pi AFP - Step 06 - Drives in finder

At this point, you should now have the Apple Filing Protocol running on your Raspberry Pi. You should also be able to use a MAC OS X device to connect to your shared folders over the AFP protocol successfully.

If you have any feedback regarding this tutorial, then please don’t hesitate to leave a comment below.

Get tutorials delivered to your inbox weekly.