5 months ago

Samba: Set up a Raspberry Pi as a File Server for your local network

Turn your Raspberry Pi into a Samba file server to back up and share content from anywhere on your local network

It’s easy to use a Pi as a Samba file server where you can store backups and share files from all the other computers on your network.

Samba is the Linux implementation of the SMB/CIFS file sharing standard used by Windows PCs and Apple computers, and widely supported by media streamers, games consoles and mobile apps.

This tutorial assumes that you’ll use a keyboard, mouse, and monitor to set up your file server, but you can alternatively enable SSH and connect to it remotely from another computer on your local network.

We also assume you’re using a 32GB (or smaller) micro SD card, which provides a reasonable amount of storage space without requiring any extra steps to make it accessible. However, if you need extra storage, it’s easy to mount a large external USB drive and create a Samba entry for it.

Alternatively, if you want to keep things compact, you can install Raspbian on micro SD cards of up to 256GB, although we suggest checking online (non-working SD cards) before you buy to make sure you get one that’s fully compatible with the Raspberry Pi.

Once set up, you can mount your home file server on all the other computers on your network, and use it as a convenient place to store everything from music files you want to share with your housemates, to backups of important documents and save-game files you’d like to share between computers.

We recommend using a wired Ethernet connection for stability and fast transfer speeds. The project will still work if you connect your Pi via WiFi, although performance will be affected, particularly when it comes to copying over large files.

File Server: Set up Samba

Download the latest version of NOOBS and copy it to a blank micro SD card that’s been formatted as fat32. Plug the micro SD card into your Pi, boot it up and opt to install Raspbian with a PIXEL desktop.

 

Samba is available in Raspbian’s standard software repositories. We’re going to update our repository index, make sure our operating system is fully updated, and install Samba using apt-get. Open a Terminal and type:

Create your shared directory

We’re going to create a dedicated shared directory on our Pi’s micro SD hard disk. You can put it anywhere, but ours will be at the top level of the root file system.

This command sets the sticky bit (1) to help prevent the directory from being accidentally deleted and gives everyone read/write/execute (777) permissions on it.

Configure Samba to share your new directory

Samba Config files

Edit Samba’s config files to make the file share visible to the Windows PCs on the network.

In our example, you’ll need to add the following entry:

This means that anyone will be able to read, write, and execute files in the share, either by logging in as a Samba user (which we’ll set up below) or as a guest. If you don’t want to allow guest users, omit the guest ok = yes line.

You could also use Samba to share a user’s home directory so they can access it from elsewhere on the network, or to share a larger external hard disk that lives at a fixed mount point. Just create a smb.conf entry for any path you want to share, and it’ll be made available across your network when you restart Samba.

Create a user and start Samba

 

Before we start the server, you’ll want to set a Samba password – this is not the same as your standard default password (raspberry), but there’s no harm in reusing this if you want to, as this is a low-security, local network project.

Then set a password as prompted. Finally, let’s restart Samba:

From now on, Samba will start automatically whenever you power on your Pi. Once you’ve made sure that you can locate your shared folder on the network, you can safely disconnect the mouse, monitor, and keyboard from your Pi and just leave it running as a headless file server.

Find your Pi on the network

You’ll now be able to find your Raspberry Pi file server (named RASPBERRYPI by default) from any device on your local network. If you’ve left smb.conf’s default settings as they are, it will appear in a Windows network workgroup called WORKGROUP.

Pi-Zero-Case

  • Rich C.

    “PI AS A FILE SERVER” vs “PI AS A FILE SEVER”

  • John Lockard

    Maybe it’s wireless and they’re using “sever” to emphasize the cutting of the cord…

  • Rich C.

    Lol! Indeed! 🙂

  • umang malik

    How do I add external storage drives?

  • obieq

    you should check letter and mount then
    fdisk – l

    mkdir mntusb
    sudo mount devsda1 mntusb
    (nano etcfstab – for automount)

  • Josh Blagden

    Why is it that when you plug an external drive into a computer running a desktop Linux distribution, mounting is done automatically, but when you plug an external drive into a computer running a server Linux distribution, mounting has to be done manually?

  • jason luong

    Newbie question here.

    I have been looking a solution where one RPi3 acts as both a NAS and a media player. So far the NAS part is handled by OMV and the media player part is OSMC which results in 2 Pi computers. Based on what I have read in this article, can I install SAMBA inside OSMC? This way, I still have OSMC with the added ability to put in media files over the network without having to physically remove the external USB drive and put the media files in it and then reattach it back to the Pi?

  • Paul

    I built one of these using a USB drive enclosure containing a 2.5″ drive. I noticed that the drive spins continuously. Is there a way to have the drive sit idle while not in use?

  • Maxim Schaff

    it says smaba: command not found

  • hurpmcdurp

    “smaba”

  • Michael Bleck

    Samba Not Smaba

  • disqus_yd8waYAXGs

    So my Windows laptop can see the share, but tells me it can’t access (network path was not found). My Linux Mint laptop cannot even see the share for no apparent reason. I’ve got a share folder and 2 external drives being shared, and the WIndows machine can see all three folders, but that’s it. Can anyone help?

  • Lan Shenghai

    Excute “net use” in windows termial box
    It will display all the links.

    And run following command to remove your PI’s link:
    net use /D \192.168.0.165share

  • Maddie

    I did this (found the guide somewhere else) and plugged two external HDD drives into my Rpi 3 one, an old laptop external drive I’ve had for years, 500 GB, got it up and running, I thought well this is nice, but not awesome, not yet, what would make it awesome is upgrade it with an insane amount of storage so I went to an online retailer and found an 8 TB self powered external HDD and set that up (after imaging all my computers HDD) now I have all my movies, videos, and music on network drives ( I partitioned the drive into many logical drive)

  • Pieter Degrande

    followed the tutorial, not working.
    sudo /etc/init.d/samba restart
    sudo: /etc/init.d/samba: command not found
    this happens to me every time I try anything in linux. I always end up wasting hours on google distilling a solution that actually works.