Musings of a Programmer

Rarely-used blog of Dan Harper.
View all blog posts

Raspberry Pi 2, Samba

February 26, 2015

  1. Installing Raspbian
  2. Auto-Mounting USB Drives
  3. Transmission
  4. SickBeard
  5. CouchPotato
  6. MiniDLNA
  7. Samba

Samba allows you to share directories across the network, where they'll be visible as Shared Drives on Mac/Windows/Linux etc.

To get started, install it:

sudo apt-get install samba samba-common-bin

Now, configure it:

sudo vim /etc/samba/smb.conf

Let's enable Username/Password-based security on our shared drives (this part is entirely optional), just un-comment (remove the #) the user security line under the Authentication block:

security = user

Now, at the bottom of the file, let's configure a single shared drive - in this case it's my entire external drive:

[Elements]
comment = External Drive
path = /mnt/usbel
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no

The [Elements] is the name the directory will show as to connecting clients. Here we're granting read/write access (read only = no) to all users part of the "users" Unix group (valid users = @users), and force all files written to be owned by the same "users" group (force group = users).

It seems you can get pretty expressive with Samba rules, as this page in the docs shows. For example, you can configure read-access for some users or guests, and grant write for others.

Finally, Samba users are not the same as your Unix users. You have to explictly grant individual user accounts Samba access. Let's add our default pi user (who is already part of the users group):

sudo smbpasswd -a pi

This will prompt you for a password to use for Samba access.

To add other users, they must have a Unix account on the machine first, e.g. with sudo useradd danharper -m -G users, sudo passwd danharper then sudo smbpasswd -a danharper.

To finalise your changes, reboot Samba:

sudo service samba restart

You should now see your server under "Shared" in Finder's sidebar on Mac, and wherever Windows puts these (Computer > Network ?):

IMAGE NOT FOUND: /content/images/2015/02/Untitled-2.png
generate-image-sizes.

IMAGE NOT FOUND: /content/images/2015/02/Untitled.png
generate-image-sizes.