Samba-Server on Raspberry-Pi

Today I decided to give my Raspberry Pi something to do. Now it is a samba fileserver for my Macbook Backup. It was not quite easy to setup Time Machine on my Macbook to use a samba share as backup-device, but at least it works.

[TOC]

Samba on Raspberry

On my Raspberry Pi I use Raspberrian as OS.

install required packages

To setup a samba server, I had to install the required packages first:

$ sudo apt-get update
    $ sudo apt-get install samba samba-common-bin samba-tools

configure samba

The configuration of samba is located at /etc/samba/smb.conf.

First, I moved the example configuration away:

$ sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.orig

Now I started to create a new one sudo vim /etc/samba/smb.conf and inserted the following stuff:

[global]
        workgroup = HOME
        netbios name = RASPBERRYPI
        server string = RASPBERRYPI.HOME.LAN
        security = user
        passdb backend = tdbsam
        encrypt passwords = yes
    [backup]
        path = /media/backup
        valid users = max
        read list = max
        write list = max
        read only = No
        create mask = 0664
        directory mask = 0775

At [global] section I configure generall settings. workgroup configures the working group and netbios name is the name of the computer (here Raspberry) which should appear later in network. A short description can be done with server string.
With security = user I set the security level of Samba to user. This is the default since Samba 2.0. In the user-level, every user had to authenticate himself before he can use the samba drive.
passdb backend configures the Userdatabase backend of Samba. tdbsam is the newest format for this.
The option encrypt passwords should be set to yes to encrypt passwords between clients and the server.

check settings

To check the syntax of /etc/samba/smb.conf we can use the program testparm. This should be done after every manual change in the config file to avoid syntax errors.

$ sudo testparm -s

After the syntax-check, I checked if all folders I configured in smb.conf exists:

$ sudo mkdir -p /media/backup
    $ sudo chown max. /media/backup

configure user accounts

All users configured in /etc/samba/smb.conf need a existing user-account on the raspberry pi. Therefore I added the new users to group users and baned them to login via ssh.

$ sudo useradd -m -s /sbin/nologin -g users max

After that we need to add the user to the user database of samba and set a password to enable samba-login later:

$ sudo smbpasswd -a max

start samba

At least we have to restart our samba daemon:

$ sudo service samba restart
    [ ok ] Stopping Samba daemons: nmbd smbd.
    [ ok ] Starting Samba daemons: nmbd smbd.

use external storage

I just have a 4 GB SD-Card on my Raspberry. This is a little bit less space for a samba server. So, I use a external usb harddisk with external power supply to extend my samba storage.

I had a external harddisk of my macbook, formated with hfsplus. Debian or Raspbian is able to read hfsplus after some configuration.

enable hfsplus

I installed following packages:

$ sudo apt-get install hfsplus hfsutils hfsprogs

adapt fstab

It is quite annoying if you have to mount the external storage by hand after every reboot. To prevent this, I just added it to /etc/fstab:

/dev/sda1   /media/backup    hfsplus rw,auto,nouser,exec 0 0

reload fstab

To reload the /etc/fstab you can just type

$ mount -a
comments powered by Disqus