That's an excellent idea! Setting up a SAMBA File Sharing Server on a Raspberry Pi is a common and practical project.
Here is a structured, detailed GitHub Documentation that you can use as a template for your repository's README.md file, outlining the project, setup steps, and configuration.
This project details the setup of a secure and reliable network-attached storage (NAS) solution using a Raspberry Pi 4 Model B and the SAMBA file-sharing protocol. SAMBA allows Linux-based systems to provide file and print services to Windows, macOS, and other Linux clients over a local network.
This setup transforms the Raspberry Pi into a dedicated file server, enabling easy, cross-platform access for storing and sharing files.
- Cross-Platform Access: Seamless file sharing with Windows, macOS, and Linux clients.
- Secure Authentication: User-level security using SAMBA passwords.
- Network Storage: Utilizes a connected hard drive/MicroSD for centralized storage.
- Headless Operation: Can run without a monitor or keyboard once configured.
| Category | Component | Notes |
|---|---|---|
| Hardware | Raspberry Pi 4 Model B (2GB/4GB) | Used as the server host. |
| MicroSD Card ( |
For the Raspberry Pi OS. | |
| External Storage (Optional) | USB Hard Drive or SSD for large file storage. | |
| Ethernet/WiFi Connectivity | Required for network access. | |
| Software | Raspberry Pi OS (Lite recommended) | The operating system (we used the 64-bit version). |
| SAMBA Package | The core software for the file-sharing protocol. | |
| Linux Utilities |
fdisk, mount, chown for disk and permission management. |
- Install OS: Flash the latest Raspberry Pi OS onto the MicroSD card.
- Enable SSH: For headless setup, enable SSH via the
raspi-configtool or by placing an empty file namedsshin the boot partition. - Update System: Access the Pi via SSH and run the following commands:
sudo apt update sudo apt full-upgrade -y
Install the SAMBA daemon and required utilities:
sudo apt install samba samba-common-bin -yCreate a directory that will be shared across the network.
- Create Directory:
# Create a general share directory sudo mkdir -p /mnt/samba/myshare - Set Permissions: Grant full ownership of the directory to the default Pi user to simplify access for testing.
Note: For production, use specific user/group permissions.
sudo chown -R pi:pi /mnt/samba/myshare sudo chmod -R 0775 /mnt/samba/myshare
Edit the main SAMBA configuration file to define the shared folder.
- Backup the original config:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
- Open the config file:
sudo nano /etc/samba/smb.conf
- Add the Share Definition: Scroll to the bottom of the file and add the following block:
[myshare] comment = Raspberry Pi File Share path = /mnt/samba/myshare browseable = yes writeable = yes valid users = pi create mask = 0775 directory mask = 0775 public = no read only = no
SAMBA requires its own password database, separate from the Linux system password.
- Add the user (e.g.,
pi) to SAMBA:sudo smbpasswd -a pi # Enter a strong password when prompted (it can be the same as your Linux password or different)
Apply the changes by restarting the SAMBA services:
sudo systemctl restart smbd
sudo systemctl restart nmbdThe output you showed, samba.service... Active: active (running), confirms this step was successful.
Clients on the network can now access the share using the following methods:
| Operating System | Access Method | Example Path |
|---|---|---|
| Windows | File Explorer, Network Location | \\<Pi's_IP_Address>\myshare |
| macOS | Go |
smb://<Pi's_IP_Address>/myshare |
| Linux (Nautilus/Thunar) | Connect to Server | smb://<Pi's_IP_Address>/myshare |
You will be prompted to enter the username (pi) and the SAMBA password you set in Step 5.
| Command | Purpose | Output Example (Relevant) |
|---|---|---|
ip a |
Check the Raspberry Pi's IP address. | inet 192.168.x.y/24 |
sudo systemctl status smbd |
Verify the SAMBA service is running. | Active: active (running) |
testparm |
Check for syntax errors in smb.conf. |
Loaded services file OK. |
- Dedicated Drive: Integrate an external USB drive and mount it persistently to
/mnt/samba/mysharefor increased storage. - Security: Create dedicated, non-root users and set more restrictive permissions (e.g., read-only access for certain shares).
- Performance: Optimize the
smb.confsettings for faster read/write speeds.