Skip to content
GEEKnodes

Raspberry Pi

Samba on Raspberry Pi: Share Folders and USB Drives

Set up a Samba file server on Raspberry Pi to share a folder or USB drive with Windows and macOS: install, smb.conf, permissions and errors.

With Samba, a Raspberry Pi becomes a small file server: a folder or USB drive you see from Windows and macOS like any network drive. This guide explains how to install it, mount the drive reliably and connect from both systems.

In short

  • Samba implements SMB, the file sharing protocol Windows and macOS understand without installing anything.
  • It is configured in /etc/samba/smb.conf and each user needs a separate Samba password (smbpasswd -a).
  • For a USB drive, mount it by UUID in /etc/fstab with the nofail option so the Pi boots even if it is missing.

You need an updated Raspberry Pi OS, SSH access and ideally a static IP.

What you will build

Raspberry Pi 192.168.1.10 with a USB drive shares the compartido and disco resources over SMB with a Windows PC and a Mac
A Pi with Samba serves a folder and a USB drive to Windows and macOS.
ItemExample in this guide
Raspberry Pi IP192.168.1.10
Pi userpi
Shared folder/srv/compartido or the drive at /mnt/disco
Network share namecompartido and disco

Change these values to yours.

Step 1: install Samba

sudo apt update
sudo apt install samba samba-common-bin

If it asks about WINS/DHCP configuration during install, answer No.

Step 2: create the shared folder

sudo mkdir -p /srv/compartido
sudo chown pi:pi /srv/compartido

The owner matters: Samba accesses files with the permissions of the Linux user you connect with. If the folder belongs to root, you will see it but not write.

Step 3: prepare a USB drive (optional)

If you want to share an external drive, connect it and find it:

lsblk -f

You will see something like:

NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda
└─sda1 ext4   datos 3f2a1c9e-7b4d-4e0a-9c1f-1a2b3c4d5e6f

Which file system to use

FormatRecommendation
ext4Best if the drive stays on the Pi: Linux permissions, robust and fast
exFATUseful if you sometimes plug it straight into Windows or Mac
NTFSWorks, but with more permission limitations

To choose in more detail, see file systems explained.

Mount it permanently

Create the mount point and edit /etc/fstab:

sudo mkdir -p /mnt/disco
sudo nano /etc/fstab
fstab line: drive UUID, mount point /mnt/disco, ext4 and nofail option to boot even without the drive
Mount by UUID with nofail: the Pi boots even if the drive is missing.

Add a line with your drive’s UUID:

UUID=3f2a1c9e-7b4d-4e0a-9c1f-1a2b3c4d5e6f  /mnt/disco  ext4  defaults,nofail  0  2
  • UUID instead of /dev/sda1: the sda name can change if you connect another drive.
  • nofail: if the drive is absent, the Pi boots anyway instead of stalling.

Test the line without rebooting and set permissions:

sudo systemctl daemon-reload
sudo mount -a
sudo chown pi:pi /mnt/disco

If mount -a gives no errors, you are good.

Step 4: configure the shares

Back up the original file and edit it:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orig
sudo nano /etc/samba/smb.conf

At the end of the file, add:

[compartido]
   path = /srv/compartido
   browseable = yes
   read only = no
   valid users = pi
   create mask = 0664
   directory mask = 0775

[disco]
   path = /mnt/disco
   browseable = yes
   read only = no
   valid users = pi
OptionWhat it does
pathActual folder shared
browseableAppears when browsing the server
read only = noAllows writing
valid usersOnly those users can enter
create mask / directory maskPermissions of new files and folders

Check the syntax:

testparm

Step 5: create the Samba password

Samba does not use the Linux password. Create one for the user:

sudo smbpasswd -a pi

Restart the service:

sudo systemctl restart smbd

Step 6: connect from Windows

  1. Open File Explorer.
  2. In the address bar type \\192.168.1.10\compartido and press Enter.
  3. Enter user pi and the Samba password.

To keep it as a fixed drive, right-click This PC → Map network drive, pick a letter and paste the same path. From the console:

net use Z: \\192.168.1.10\compartido /user:pi /persistent:yes

Step 7: connect from macOS

  1. In the Finder, menu Go → Connect to Server (⌘K).
  2. Type smb://192.168.1.10/compartido and click Connect.
  3. Choose Registered User and enter pi and the Samba password.

To mount it at login, add the mounted volume to Login Items under System Settings → General.

Common problems

SymptomCause and fix
Access denied when writingThe folder belongs to root. Use chown with your user
The password does not workYou missed smbpasswd -a or are using the Linux one. They differ
Windows cannot find the serverUse the IP directly instead of the name
The drive share looks emptyThe drive is not mounted. Check lsblk and mount -a
The Pi will not boot after editing fstabError in the line and nofail missing. Fix /etc/fstab from another computer reading the microSD
Slow transfersWi-Fi or USB 2.0 drive. Use cable and a USB 3.0 (blue) port

If the problem is on the Windows side, see Windows is not sharing folders or printers.

Frequently asked questions

Can I set up guest access without a password?

You can, but current Windows versions block SMB guest access by default for security. Using a user and password avoids problems.

Does it count as a backup?

It is a good backup destination, but a single drive is not a backup: if it fails, you lose everything. Read RAID explained to understand why.

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor