Raspberry Pi Samba: How to Set Up a Simple and Secure File Server for Your Home Network

Raspberry Pi Samba: How to Set Up a Simple and Secure File Server for Your Home Network

Oct 17th,2025

Raspberry Pi board with text

Why Use Samba on Raspberry Pi?

Raspberry Pi Samba allows users to easily share folders across Windows, macOS, and Linux systems, thanks to its open-source implementation of the SMB/CIFS protocol.Thanks to Samba, the open-source implementation of the SMB/CIFS protocol, a Raspberry Pi can share folders across Windows, macOS, and Linux systems with minimal effort.

The main motivation for using a Raspberry Pi file server with Samba is cost-efficiency, making it a practical choice for personal or small office networks.While commercial NAS devices from Synology or QNAP provide elegant web interfaces and redundancy options, they can be expensive and consume significantly more power. A Raspberry Pi running 24/7 typically draws less than 10 W, making it ideal for personal backups, multimedia sharing, or small office environments — for maker education ideas using Raspberry Pi, check SunFounder’s Maker Education page.Of course, there are trade-offs. Commercial NAS devices include RAID management, hot-swappable drives, and advanced snapshot systems.A Raspberry Pi lacks these enterprise features, but for many makers, students, and small businesses, it provides an accessible entry-level NAS — a perfect starting point for anyone building a Raspberry Pi NAS.This guide targets users comfortable with Linux who want to turn their Raspberry Pi into a secure and dependable network share server.

What Is Samba?

Samba implements the Server Message Block (SMB) and Common Internet File System (CIFS) protocols, enabling file and printer sharing between UNIX-like and Windows systems. It allows a Linux server (like a Raspberry Pi) to appear as a Windows file sIt allows a Linux server (like a Raspberry Pi) to appear as a Windows file server on the network — a fundamental part of any Samba server setup.

Diagram showing Raspberry Pi as a Samba file server connected to multiple computers and network devices

Protocol Compatibility

Modern Samba versions support SMB 2 and SMB 3, offering encryption, improved performance, and compatibility with Windows 10/11 and macOS — you can also see how Samba is installed in OSMC by following the Install Kodi on Raspberry Pi — Samba setup guide.The legacy SMB 1 protocol is disabled by default due to known vulnerabilities. Maintaining up-to-date packages ensures the highest security and interoperability with modern clients.

Hardware and System Setup

A stable Raspberry Pi network storage setup begins with solid hardware, including a reliable power supply and external SSD or HDD.Recommended components include:
Raspberry Pi 4 or 5 with gigabit Ethernet
High-quality 5 V / 3 A PSU
External SSD/HDD for storage
1.Mounting File Systems
Most external drives are formatted as NTFS or exFAT for Windows compatibility, but Linux performs best with ext4,which ensures better performance and reliability for your Raspberry Pi NAS. If you prefer cross-platform access, NTFS works well using the ntfs-3g driver. To mount automatically, edit /etc/fstab using the UUID of the drive:
sudo blkid

Terminal output showing Raspberry Pi identifying external USB storage using sudo blkid command for Samba setup

sudo nano /etc/fstab
Example entry:
UUID=6803CC6E2309FCA2 /media/storage ntfs defaults,uid=pi,gid=pi,umask=000 0 0

Editing /etc/fstab in Nano on Raspberry Pi to auto-mount USB storage for Samba file sharing

After editing, test with:
sudo mount -a
2.Update the System
Before installing Samba:
sudo apt update && sudo apt upgrade -y
sudo apt install ntfs-3g

Installing Samba on Raspberry Pi

Samba is available in the default repositories of Raspberry Pi OS, Debian, and Ubuntu, making Samba configuration on Raspberry Pi straightforward even for beginners:
sudo apt install samba samba-common-bin -y
Verify installation and service status:
systemctl status smbd
You should see active (running) indicating that the daemon is ready.

Checking Samba smbd service status on Raspberry Pi terminal showing active and running stateWindows terminal showing idf.py --version output with a “component_manager_ext” warning, confirming ESP-IDF v5.5.1.

Configuring Samba Share

Configuring the Shared Folder

In a typical Raspberry Pi SMB setup, the shared folder is created and assigned proper permissions before editing the Samba configuration file.Create a directory for shared content:
sudo mkdir -p /media/usb-storage/shared
sudo chmod -R 775 /media/usb-storage/shared

File manager view on Raspberry Pi showing USB storage mounted at /media/USB-STORAGE with shared folder

Edit the configuration file:
sudo nano /etc/samba/smb.conf
At the bottom, define the shared resource:
[Shared]
path = p /media/usb-storage/shared
browseable = yes
writable = yes
valid users = pi
create mask = 0775
directory mask = 0775

Editing Samba configuration file smb.conf in Nano on Raspberry Pi to set up shared folder permissions

Global Section
The top [global] block defines server-wide parameters:
[global]
   workgroup = WORKGROUP
    server string = RaspberryPi File Server
   security = user
   interfaces = eth0
   log file = /var/log/samba/%m.log
   max log size = 1000

Managing Samba Users

Samba users are independent from Linux accounts, though they map to them — a key step in maintaining a secure Samba Raspberry Pi environment.First, ensure the Linux user exists:
sudo adduser pi
Then add the same user to Samba:
sudo smbpasswd -a pi
Restart the service:
sudo systemctl restart smbd
Set directory ownership to guarantee write access:
sudo chown -R pi:pi /media/usb-storage/shared
For fine-grained control, access control lists (ACLs) can be applied using setfacl for multi-user environments — see the Linux ACL how-to for detailed usage examples.

Accessing the Shared Folder

From Windows
To connect via SMB file sharing, open File Explorer on Windows and enter \\raspberrypi\Shared to access your files.Open File Explorer and type:
\\raspberrypi\Shared
or
\\<Pi_IP_Address>\Shared
Use the Samba credentials created earlier. You can right-click and Map Network Drive to reconnect automatically at login — see SunFounder's “Map network drive” instructions in their Rascam docs for how this is done.

Windows File Explorer showing Raspberry Pi Samba shared folders accessed via network address 192.168.100.110

Folder shared with a new example folder “SunFounder”

Windows File Explorer showing Raspberry Pi Samba shared folders accessed via network address 192.168.100.110

From Linux
Mount using CIFS:
sudo apt install cifs-utils
sudo mkdir /mnt/shared
sudo mount -t cifs //raspberrypi/Shared /mnt/shared -o username=pi

Mounting a Windows Samba shared folder on Raspberry Pi using CIFS command in terminal

Auto-Mount and Startup

Auto-Mount External Drives
To ensure your external disk mounts on each boot, add its UUID to /etc/fstab as described earlier. Always test after rebooting to confirm, ensuring your DIY NAS Raspberry Pi functions reliably each time the system starts.
Enable Samba at Startup
Samba services start automatically, but verify:
sudo systemctl enable smbd nmbd

Enabling Samba services smbd and nmbd on Raspberry Pi using systemctl command in terminal

If the drive mounts slowly, Samba might start before the volume is available. Create a small delay in
/etc/systemd/system/smbd.service.d/override.conf:
[Service]
ExecStartPre=/bin/sleep 10

Security, Stability, and Performance
Optimization

A shared Raspberry Pi home server must balance accessibility with protection by enforcing encryption and firewall rules.
Disable Outdated Protocols
Add to [global]:
min protocol = SMB2
This blocks insecure SMB 1 connections.

Use Encryption and Signing
To protect data over untrusted networks:
smb encrypt = required
This enforces encryption compatible with SMB 3 clients.

Firewall and Network Rules
Limit access to trusted subnets:
hosts allow = 192.168.1.0/24
Configure the Uncomplicated Firewall (UFW) if installed:
sudo ufw allow samba

Logging and Auditing
Enable detailed logs for troubleshooting:
log level = 2 log file = /var/log/samba/%m.log

Rotate logs regularly to prevent disk saturation.

Performance Tuning
Network throughput on Raspberry Pi 4/5 can exceed 80–100 MB/s with proper optimization — for benchmark data and optimization techniques, see the Raspberry Pi foundation performance guide. Recommended tweaks:socket options = TCP_NODELAY SO_RCVBUF=65536 SO_SNDBUF=65536
aio read size = 16384
aio write size = 16384

Resource and Concurrency Management
Samba is multi-threaded. On systems with limited RAM (1–2 GB), restrict simultaneous connections:
max smbd processes = 10
Monitoring tools such as htop or iotop help ensure that disk I/O and CPU load remain within safe limits during transfers — see SunFounder's Raspberry Pi Web Server guide for using htop in real-time monitoring.

Conclusion

Raspberry Pi Samba setup is one of the simplest and most rewarding ways to turn your Raspberry Pi into a practical home file server.With just a few commands, you can share folders seamlessly across Windows, Linux, and macOS devices, all while keeping costs and power consumption minimal. By following the configuration, security, and optimization steps in this guide, your Raspberry Pi can serve as a reliable and efficient storage hub for personal use or small office environments. Whether you’re backing up files, streaming media, or collaborating within a local network, Samba makes your Raspberry Pi an essential part of your digital ecosystem.

Back to News Installing ESP-IDF Official Development Framework: Step-by-Step Setup Guide for ESP32