The 100 best digital picture frames on amazon
The 100 best digital picture frames on amazon
The 100 best digital picture frames on amazon
The 100 best digital picture frames on amazon

Installing Sam­ba on your Rasp­berry Pi Buster and opti­miz­ing it for macOS com­put­ers

-

File shar­ing is one of the basic func­tion­al­i­ties of an oper­at­ing sys­tem. But if you install Buster on your Rasp­berry Pi, you still need to add the Sam­ba soft­ware to make your Pi acces­si­ble in a Windows/macOS or Lin­ux envi­ron­ment.

Although this is rel­a­tive­ly straight for­ward, there are sev­er­al things that have changed over time and many tuto­ri­als on the web are out­dat­ed in this regard. After all, Sam­ba has been around since 1992 to pro­vide file and print ser­vices to all man­ner of SMB/CIFS clients.

The recent Rasp­bian Buster release and Apple's shift from AFP to SMB has also brought about some changes, and this tuto­r­i­al will explain to you espe­cial­ly how to opti­mize your Rasp­berry Pi Sam­ba set­up for macOS com­put­ers in your net­work. All this will, of course, also work for con­nect­ed Win­dows and Lin­ux com­put­ers.

Prepa­ra­tion

You have installed the lat­est "Rasp­bian Buster with desk­top" ver­sion on your Pi and are con­nect­ed to the Inter­net. If you don't know how to do that, you can look here.

I also assume that you are con­nect­ed to your Rasp­berry Pi via ssh in a Ter­mi­nal win­dow.

Alter­na­tive­ly, you can do the same on your Rasp­berry Pi if you have a mon­i­tor and a key­board con­nect­ed to it. As many Pi are used as head­less sys­tems, ssh'ing into the Pi has become a pop­u­lar way.

Before you install new pack­ages, you should always run a sys­tem update with

sudo apt update && sudo apt upgrade -y

Sam­ba works with all Rasp­berry Pi mod­els, but file shar­ing is much faster with the Rasp­berry Pi 3 (the­o­ret­i­cal­ly Giga­bit but ham­pered by the USB 2.0 bus speed result­ing in ~224 Mbps) and espe­cial­ly with the Pi 4 and its Giga­bit eth­er­net port (over 900 Mbps).

If you expect decent file-shar­ing per­for­mance from your Rasp­berry Pi, get a Mod­el 4 with 2 or 4 GB of RAM.

If you only need the occa­sion­al file exchange like for a dig­i­tal pic­ture frame, then the max­i­mum speed doesn't mat­ter that much.

AFP, Bon­jour and Avahi

As I men­tioned ear­li­er, there are many Rasp­berry Pi net­work­ing tuto­ri­als on the web that sug­gest installing sev­er­al pack­ages that you don't need any­more. Let's go through the most often men­tioned ones.

Apple orig­i­nal­ly used AFP (Apple Fil­ing Pro­to­col) but moved over to SAMBA (SMB) in macOS 10.9 Mav­er­icks released in 2016. You will still find many tuto­ri­als about installing AFP with Netatalk, but I don't see any rea­son to stick with lega­cy tech­nol­o­gy. SMB 3 (the lat­est ver­sion) is faster than AFP and pro­vides all fea­tures that you would need for your Mac (like Time Machine com­pat­i­bil­i­ty). Con­clu­sion: For­get about installing AFP on your Pi, use SAMBA instead.

Bon­jour is Apple's won­der­ful tech­nol­o­gy that auto­mat­i­cal­ly locates and dis­plays devices and ser­vices like com­put­ers, file shares, or print­ers that are avail­able on a net­work. It is built in macOS but also avail­able for Microsoft Win­dows. To allow the Rasp­berry Pi to prop­a­gate itself across a net­work and to be rec­og­nized by Bon­jour, you need­ed to install the Avahi pack­age sep­a­rate­ly. The lat­est Rasp­bian Buster ver­sion includes this right out of the box, so no need for installing it.

To sum­ma­rize: All you need for Rasp­berry Pi file shar­ing is SAMBA.

Installing Sam­ba

In the Ter­mi­nal win­dow enter

sudo apt install samba -y

When this win­dow comes up, choose "No".

If you want to access oth­er net­work com­put­ers from your Rasp­berry Pi, e.g., when you use it as a desk­top com­put­er, you will need also to install the CIFS tools. They were orig­i­nal­ly part of the Sam­ba pack­age but lat­er split into their own pack­age.

For an appli­ca­tion like a dig­i­tal pic­ture frame where you don't need to see oth­er com­put­ers but just be vis­i­ble in the net­work your­self, you won't need to install this.

sudo apt install samba-client cifs-utils

Installing a user

This is very easy. If your user­name is "pi", type

sudo smbpasswd -a pi

Just replace pi with what­ev­er your user name is, set a pass­word and con­firm it. You can add as many users as you like.

The SAMBA con­fig file

SAMBA comes with an elab­o­rate con­fig file that allows you to spec­i­fy your net­work exact­ly as you want it. When you open it for the first time, you might be slight­ly over­whelmed by its length, but most of the file is just filled with instruc­tions and expla­na­tions. The core is quite com­pact.

If you like, you can delete all the "#" com­ments (CTRL-K to remove lines in the edi­tor), but they won't make your sys­tem faster. Just a bit more Marie-Kon­­do-min­i­­mal.

Open the SAMBA con­fig file with

sudo nano /etc/samba/smb.conf

The con­fig files has two main seg­ments: Glob­al Set­tings and Share Def­i­n­i­tions.

In Glob­al Set­tings, you define the gen­er­al behav­ior, like authen­ti­ca­tion, net­work restric­tions, and log­ging.

The Share Def­i­n­i­tions spec­i­fy the fold­ers that you want to share and the kind of access that you want to grant to users, groups and every­one else. The print­er net­work is also in this sec­tion.

To opti­mize the glob­al sec­tion for macOS com­put­ers in your net­work, you may find the fol­low­ing lines quite use­ful.

They add some tweaks for macOS and cre­ate a nice side­bar sym­bol for the Rasp­berry Pi (based on the Rack­Mac). I found that not doing this would cre­ate a rather unsight­ly ques­tion mark sym­bol next to my Rasp­berry Pi share on Mod­el 4 run­ning Rasp­bian Buster.

Just add these lines direct­ly below [glob­al]:

[global]
min protocol = SMB2
vfs objects = catia fruit streams_xattr
fruit:metadata = stream
fruit:model = RackMac
fruit:posix_rename = yes
fruit:veto_appledouble = no
fruit:wipe_intentionally_left_blank_rfork = yes
fruit:delete_empty_adfiles = yes

For all full overview of the var­i­ous set­tings in this seg­ment, I rec­om­mend a look at this page.

Now scroll down to the last sec­tion called "Share Def­i­n­i­tions".

When I am work­ing on my dig­i­tal pic­ture frame project, I like to be able to access the Raspberry's home direc­to­ry. Some peo­ple will tell you that is a secu­ri­ty risk, but if you do reg­u­lar sys­tem updates and set your pass­word to some­thing else than "123" or "pi" you should be in good hands.

So to share your home direc­to­ry, or any direc­to­ry for that mat­ter, for a reg­is­tered user (like "pi") insert this code:

[pi]
   comment = Pi Directory
   path = /home/pi
   browseable = yes
   read only = no
   guest ok = no
   create mask = 0700
   directory mask = 0700
   valid user = %S

If you want to share just your Pic­tures fold­er but with every­one, put it like this:

[Pictures]
   comment = Pictures
   path = /home/pi/Pictures
   browseable = no
   read only = no
   guest ok = yes
   create mask = 0775
   directory mask = 0775

You can restrict access to your fold­ers in many ways. "0700" would only allow the user to mod­i­fy the files. For fur­ther study on this sub­ject I rec­om­mend this arti­cle.

When you are done with your mod­i­fi­ca­tions, hit CTRL + O to write the file to disk and CTRL + X to exit the edi­tor.

To test the syn­tax of your con­fig file or see a sum­ma­ry of the set­tings, enter

testparm /etc/samba/smb.conf

Final­ly, restart SAMBA:

sudo /etc/init.d/smbd restart

You should now see the name of your Rasp­berry Pi in your net­work. Con­nect to it using your user­name "pi" (in our exam­ple) and your pass­word.

When­ev­er you reboot your Rasp­berry Pi, file shar­ing will auto­mat­i­cal­ly start.

Net­work­ing is some­times a bit slow to rec­og­nize changes. If you are using macOS and you don't see your Rasp­berry Pi after you made some changes, I rec­om­mend relaunch­ing the Find­er (Apple Menu > Force Quit).

Con­clu­sion

I hope this post was help­ful for you to install SAMBA on your Rasp­berry Pi and to opti­mize it for the macOS machines on your net­work.

As always, I'd be hap­py to hear from you if you have any com­ments or sug­ges­tions.