How to set up AFP filesharing on Ubuntu
This how-to is a mashup of two different tutorials that I found on the web, but neither was up-to-date or did everything that I wanted. But thanks for to Kremalicious and damontimm for getting me started.
After struggling with using Samba for filesharing on our mac-only network (the final straw was file permissions that just wouldn’t work for everyone), I finally gave up and decided to try using AFP instead. I’d looked at it before, but it didn’t look easy to set up or production ready, but things have changed and I didn’t find it hard at all and it’s now working far better than Samba ever did.
There are two components to natural looking AFP:
(Zeroconf is the unbranded name for Bonjour, and is necessary to advertise your AFP volume over the network) In the case of Ubuntu these are provided by Netatalk and Avahi respectively, and as neither come by default on Ubuntu we have to install and configure both (but it’s not as hard as it sounds).
Solution
1. Netatalk
Since Ubuntu 9.04 Netatalk has worked “out-of-the-box”, so all you need to do is install it (and tweak the settings slightly). Run the following command to install it:
sudo apt-get install netatalk
The next step is optional, but it should make your AFP server a little quicker. By default Netatalk turns on support for filesharing with pre-OS X Macs, but this is normally redundant. To turn it off, open /etc/default/netatalk and change the matching part of the file to:
ATALKD_RUN=no PAPD_RUN=no CNID_METAD_RUN=yes AFPD_RUN=yes TIMELORD_RUN=no A2BOOT_RUN=no
The final step is to tell Netatalk which directories it should share. By default it will only share users home directories, but to share any other folders (such as shared folders), open /etc/netatalk/AppleVolumes.default and add the following to the bottom (for each directory that you wish to share):
/your/path VolumeName allow:@groupname options:usedots,upriv
There are a number of options that you can set here, for the full description see this page.
Now if you restart AFP:
sudo /etc/init.d/netatalk restart
it should be working, although you can only connect using the IP address of your Ubuntu machine. I’d recommend testing that it works at this point by opening Finder and selecting Go -> Connect To Server, then entering “afp:://yourip/”, logging in with an Ubuntu user account and making sure that it works.
2. Avahi
To install Avahi (and mDNS which helps it imitate Bonjour), run the following command:
sudo apt-get install avahi-daemon libnss-mdns
Then open /etc/nsswitch.conf and add “mdns” to the end of the following line so that it looks like this:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns
Finally we need to configure Avahi to advertise the AFP service. To do this, create a new file at /etc/avahi/services/afpd.service, and enter the following into it:
<?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> <type>_device-info._tcp</type> <port>0</port> <txt-record>model=MacPro</txt-record> </service> </service-group>
The first service tag advertises AFP (which uses port 548 by default). The second service tag tells OS X what icon to use for your Ubuntu machine in finder, you can set this to: Macmini, iMac, MacPro, Xserve, MacBook, MacBookPro or MacBookAir as appropriate.
Now if you restart Avahi using this command:
sudo /etc/init.d/avahi-daemon restart
your AFP volume should appear on any Mac on the network.
Note
Netatalk 2 doesn’t handle symbolic links how you’d expect (at best the contents of a symlink might be inaccessible). This is a design feature, not a bug, and the Netatalk team recommend avoiding their use in shared volumes.
44 Comments
Jump to comment form | comment rss [?] | trackback uri [?]