How to install Samba on a Raspberry Pi

In this posting, we will be installing samba file sharing on a Raspberry Pi.

Preparation of the Raspberry Pi

  • Follow the instructions at How to install the Raspbian OS on a Raspberry Pi.
  • Change the hostname of your Raspberry Pi to something more meaningful by logging on to the device as user “pi” and issuing the command:

    sudo raspi-config

  • Select “Advanced Options” and set the following:
    • Hostname = pi-samba (or whatever you want to call it).
  • Select Finish
  • Reboot the Raspberry Pi

Installing samba

In the next set of instructions, we are going to install samba, which will allow us to share a directory on pi-samba with other computers on the network. This directory will be configured as writable for Windows user “smith”.

  • Update the packages:

    sudo apt-get update

  • Install samba on the Raspberry Pi:

    sudo apt-get install samba samba-common-bin

  • Change into the directory containg the samba configuration file:

    cd /etc/samba/

  • Backup the original configuration file:

    sudo mv smb.conf backsmb.conf

  • Edit the samba configuration file with:

    sudo vi /etc/samba/smb.conf

    …and replace the content with the following, obviously changing the workgroup (XXX) as appropriate:

    workgroup = XXX
    server string = My Samba Share %v
    security = user
    map to guest = bad user
    dns proxy = no
    hosts deny = ALL
    hosts allow = 192.168.0.
    comment = This is a shared folder
    path = /home/smith/share1
    browsable = yes
    guest ok = no
    read only = no
    writeable = yes
    valid users = smith
    force user = smith
    force group = smith
    create mask = 0644

  • Create a user on the Raspberry Pi, with the same name as the Windows user you intend to connect with:

    sudo adduser smith
    You will be prompted for a password, which can be anything you like.

  • Create a user on the Raspberry Pi which will be used by samba. The name should be the same as the one you created in the last step, and match the name of the Windows user:

    sudo smbpasswd -a smith
    You will be prompted for a password, which should be the same as the one the user uses on Windows. This will prevent them having to sign in when they access the share.

  • Create the appropriate directory with:

    sudo mkdir -p /home/smith/share1

  • Change the ownership of the shared directory so that it matches our new user

    sudo chown -R smith:smith /home/smith/share1

  • Restart samba with:

    sudo service samba restart

You should now be able to browse to this share using your Windows PC.

Further steps

Storing the files on the Raspberry Pi’s SD card is not an ideal choice, as we want to reduce writes to the SD card as much as possible (to prolong its life), and it is an expensive option in terms of cost per megabyte. It is relatively easy to add a USB hard disk to the Raspberry Pi. More detailed information can be found at