We use cookies

We use cookies and similar technologies to enhance your browsing experience, analyze site traffic, and personalize content and ads. By clicking "Accept", you consent to our use of cookies. Learn more in our Privacy Policy.

Turn Your Raspberry Pi Into a Simple Samba File Server

Raspberry PiDecember 9, 2025

Introduction

Ever wished you had a central place on your home network to store files, share documents, or stream media without constantly plugging in USB drives? That's where a Samba server on your Raspberry Pi comes in! Samba is an open-source implementation of the Server Message Block (SMB) protocol, which is what Windows uses for file sharing. This means you can easily access files stored on your Raspberry Pi from any computer (Windows, macOS, or Linux) on your network.

Setting up a Samba server on your Raspberry Pi is a fantastic and practical project for anyone looking to create a DIY network-attached storage (NAS) solution, a central backup point, or a personal media server. Best of all, it's surprisingly straightforward. Let's get started!

Prerequisites

Before we dive in, make sure you have the following:

  • Raspberry Pi: Any model will do, but newer models offer better performance.
  • Operating System: Raspberry Pi OS (formerly Raspbian) installed and configured.
  • Network Connection: Your Raspberry Pi should be connected to your local network (Ethernet or Wi-Fi).
  • SSH Access (Optional but Recommended): For managing your Pi remotely without a monitor and keyboard. If you're new to SSH, check out this guide on setting up SSH on Raspberry Pi.
  • Basic Linux Command Line Knowledge: We'll be using a few commands, but don't worry, we'll walk through each one.

Step 1: Update Your Raspberry Pi

It's always a good practice to start by ensuring your Raspberry Pi's software is up to date. This ensures you have the latest security patches and software versions.

Open a terminal (or connect via SSH) and run the following commands:

bash
sudo apt update sudo apt upgrade -y
  • text
    sudo apt update
    refreshes the list of available packages.
  • text
    sudo apt upgrade -y
    installs all pending updates. The
    text
    -y
    flag automatically confirms any prompts.

Step 2: Install Samba

Now, let's install the Samba package. This package provides all the necessary tools to turn your Pi into a file server.

bash
sudo apt install samba samba-common-bin -y
  • text
    samba
    is the main server package.
  • text
    samba-common-bin
    provides utilities for Samba.

Step 3: Create a Shared Directory

Next, you need a directory on your Raspberry Pi that will be shared across the network. You can create this anywhere, but a common practice is to create it in your home directory or a dedicated mount point if you're using an external USB drive.

For this tutorial, let's create a simple share called

text
myshare
in the
text
pi
user's home directory:

bash
mkdir /home/pi/myshare

Now, we need to set appropriate permissions for this directory. While

text
chmod 777
makes it writable by everyone, it's generally not recommended for security reasons. A more secure approach for a personal server is to give ownership to your user (
text
pi
in this case) and allow read/write access to that user, and potentially read-only access to others or specific groups.

For simplicity in a trusted home network, we'll make it writable by the

text
pi
user and readable/writable by a group, ensuring Samba can write to it. If you're just sharing for your
text
pi
user, this is a good starting point:

bash
sudo chown pi:pi /home/pi/myshare # Give ownership to the 'pi' user and group sudo chmod 775 /home/pi/myshare # Allow owner and group full access, others read-only
  • text
    sudo chown pi:pi /home/pi/myshare
    changes the owner and group of the directory to
    text
    pi
    .
  • text
    sudo chmod 775 /home/pi/myshare
    sets permissions: owner (
    text
    pi
    ) can read, write, execute (7); group (
    text
    pi
    ) can read, write, execute (7); others can read, execute (5).

If you want everyone on your network to be able to write without a specific user, you might need to adjust

text
chmod
further or configure Samba for guest access, but this method is more secure.

Step 4: Configure Samba

The main Samba configuration file is located at

text
/etc/samba/smb.conf
. It's crucial to back up this file before making any changes.

bash
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Now, open the configuration file using a text editor like

text
nano
:

bash
sudo nano /etc/samba/smb.conf

Scroll to the very bottom of the file and add the following section. This defines our new shared folder:

ini
[myshare] comment = Raspberry Pi Shared Folder path = /home/pi/myshare browseable = yes writable = yes create mask = 0775 directory mask = 0775 valid users = pi guest ok = no

Let's break down what these options mean:

  • text
    [myshare]
    : This is the name of your share that will appear on the network. You can choose anything descriptive.
  • text
    comment
    : A brief description of your share.
  • text
    path
    : The absolute path to the directory you created in Step 3.
  • text
    browseable = yes
    : Allows clients to see this share when browsing the network.
  • text
    writable = yes
    : Allows clients to write files to this share.
  • text
    create mask = 0775
    : Sets the maximum file permissions for new files created in the share.
  • text
    directory mask = 0775
    : Sets the maximum directory permissions for new directories created in the share.
  • text
    valid users = pi
    : Crucially, this line restricts access to only the
    text
    pi
    user. If you want to allow other users, add them separated by commas (e.g.,
    text
    valid users = pi, user2
    ).
  • text
    guest ok = no
    : This means anonymous guest access is not allowed. Users must authenticate with a username and password.

Save the file by pressing

text
Ctrl+X
, then
text
Y
to confirm, and
text
Enter
.

Step 5: Set a Samba Password

Even though your

text
pi
user has a Linux password, Samba uses its own password system. You need to set a Samba password for your
text
pi
user.

bash
sudo smbpasswd -a pi

You'll be prompted to enter and confirm a new password for the

text
pi
user for Samba. This can be different from your
text
pi
user's Linux password, but for simplicity, you might choose to keep them the same. Remember this password, as you'll need it to access the share.

Step 6: Restart Samba Service

For your changes to take effect, you need to restart the Samba services.

bash
sudo systemctl restart smbd nmbd
  • text
    smbd
    is the Samba daemon that handles file and print services.
  • text
    nmbd
    is the NetBIOS name server daemon that provides hostname resolution.

To ensure the services are running correctly, you can check their status:

bash
sudo systemctl status smbd nmbd

You should see output indicating that the services are

text
active (running)
.

Step 7: Access Your Share

Your Raspberry Pi Samba server is now ready! You can access it from any computer on your network.

From Windows

Open File Explorer and type one of the following into the address bar:

  • text
    \\raspberrypi\myshare
    (if your Raspberry Pi's hostname is
    text
    raspberrypi
    )
  • text
    \\<YOUR_RPI_IP_ADDRESS>\myshare
    (e.g.,
    text
    \\192.168.1.100\myshare
    )

You will be prompted for a username and password. Enter

text
pi
as the username and the Samba password you set in Step 5.

From macOS

  1. Open Finder.
  2. Go to
    text
    Go
    >
    text
    Connect to Server...
    (or press
    text
    Command + K
    ).
  3. In the server address field, type
    text
    smb://raspberrypi/myshare
    or
    text
    smb://<YOUR_RPI_IP_ADDRESS>/myshare
    .
  4. Click
    text
    Connect
    .
  5. Select
    text
    Registered User
    and enter
    text
    pi
    as the username and your Samba password.

From Linux

Most Linux file managers (like Nautilus for GNOME or Dolphin for KDE) allow you to connect to SMB shares. Look for a

text
Connect to Server
or
text
Other Locations
option and enter
text
smb://raspberrypi/myshare
or
text
smb://<YOUR_RPI_IP_ADDRESS>/myshare
.

Alternatively, you can use the command line:

bash
smbclient -L raspberrypi -U pi

This command lists shares on your Pi. You'll be prompted for the Samba password.

Pro Tip: Using External USB Drives

For a more robust file server, especially for media or backups, you'll likely want to use an external USB drive rather than the Pi's SD card. Here's a quick overview of the extra steps:

  1. Format the Drive: Format your USB drive to a Linux-compatible filesystem like
    text
    ext4
    or a cross-platform one like
    text
    NTFS
    .
  2. Mount the Drive: Create a mount point (e.g.,
    text
    /mnt/usbshare
    ) and permanently mount the drive using
    text
    /etc/fstab
    .
    bash
    undefined

sudo mkdir /mnt/usbshare sudo blkid # Find your USB drive's UUID

Then edit /etc/fstab: sudo nano /etc/fstab

Add a line like (replace UUID and type):

UUID=YOUR_USB_UUID /mnt/usbshare ext4 defaults,nofail 0 0

text
```

3. Adjust Permissions: Ensure the

text
pi
user (or the user you configured for Samba) has appropriate read/write permissions on the mounted USB drive's directory.
text
bash sudo chown pi:pi /mnt/usbshare sudo chmod 775 /mnt/usbshare
4. Update
text
smb.conf
:
Change the
text
path
in your
text
[myshare]
section to
text
/mnt/usbshare
.

Conclusion

Congratulations! You've successfully transformed your humble Raspberry Pi into a powerful and accessible Samba file server. You now have a central location for your files, accessible from any device on your network.

This simple setup is just the beginning. You can expand your Samba server with multiple shares, user-specific access, and even integrate it with other services like a media server (Plex, Kodi). Enjoy your newfound network storage capabilities!

Do you have any creative uses for your Raspberry Pi Samba server? Share your ideas in the comments below!

Enjoyed this article?

Share it with your network

Comments (0)

Leave a Comment

0/1000 characters

Your email will not be published. Required fields are marked *

More Articles

Raspberry PiDec 14

Schedule Tasks on Raspberry Pi: Easy Cron Job Guide

Ever wished your Raspberry Pi could just do things on its own, like taking a photo every hour, loggi...

AIDec 16

Unlock Developer Superpowers: The Benefits of OpenAI Codex

Imagine having an AI-powered co-pilot that understands your programming needs, writes boilerplate co...

AIDec 18

Claude AI vs. Cursor AI: Which Assistant Boosts Your Productivity?

!Claude vs Cursor In the rapidly evolving landscape of artificial intelligence, tools designed to ...