A quick tutorial for setting up network file sharing with read-only guest access and full access for authenticated users.
Source: Based on PCMag's Raspberry Pi NAS tutorial by Whitson Gordon
Time: ~50 minutes | Difficulty: Beginner-friendly
- Raspberry Pi (any model, Pi 4+ recommended)
- Power supply & microSD card (8GB+)
- External USB drive (wall-powered or via powered USB hub)
- Ethernet cable (optional but recommended for speed)
- Keyboard, mouse, monitor (for initial setup)
Use Raspberry Pi Imager to flash Raspbian to your microSD card. Boot up the Pi, create a password, and run initial updates.
Connect via Ethernet for faster file transfers. SSH works too if you prefer remote setup.
sudo apt update
sudo apt upgrade
sudo apt install samba samba-commonWhat this does: Updates package lists, upgrades installed packages, then installs Samba (the file-sharing software).
When prompted about WINS settings, choose Yes.
sudo fdisk -lWhat this does: Lists all connected disks. Identify your external drive (e.g., /dev/sda).
umount /dev/sda1What this does: Disconnects the drive so you can modify it. Adjust numbers if you have multiple partitions (sda2, sda3, etc.).
sudo parted /dev/sdaIn the Parted wizard, enter these commands one by one:
mklabel gpt
mkpart
When prompted, enter:
- Partition name:
MyExternalDrive(or your choice) - File system type:
ext4 - Start:
0% - End:
100%
Type quit to exit.
What this does: Creates a new GPT partition table and one partition using the entire drive.
sudo mkfs.ext4 /dev/sda1
sudo e2label /dev/sda1 MyExternalDriveWhat this does: Formats the partition with ext4 filesystem and labels it. This takes a few minutes for large drives.
sudo shutdown -r nowAfter reboot:
sudo chown -R pi:pi /media/pi/MyExternalDrive/
sudo chmod -R 755 /media/pi/MyExternalDrive/
sudo chmod 755 /media/pi/What this does: Gives your user ownership of the drive and makes directories readable by guests.
sudo nano /etc/samba/smb.confScroll to the bottom and add:
[MyMedia]
path = /media/pi/MyExternalDrive/
writeable = no
read only = yes
create mask = 0555
directory mask = 0555
public = yes
guest ok = yes
guest only = yes
browseable = yes
force user = pi
[MyMedia-Write]
path = /media/pi/MyExternalDrive/
writeable = yes
read only = no
create mask = 0775
directory mask = 0775
valid users = pi
browseable = yes
guest ok = noWhat this does:
- MyMedia = Read-only share for guests
- MyMedia-Write = Full access share requiring authentication
force user = pi= Guests borrow your user's read permissionsguest ok = yes= Allows passwordless guest access
Press Ctrl+X, then Y, then Enter to save and exit.
sudo smbpasswd -a piWhat this does: Sets a password for Samba access. Can be different from your Pi's login password.
Optional: Add more users with sudo adduser username then sudo smbpasswd -a username
sudo systemctl restart smbd nmbdWhat this does: Applies your configuration changes.
testparm -sWhat this does: Checks for syntax errors in your Samba config.
- Open File Explorer
- Type in address bar:
\\raspberrypi\MyMedia(guest access) or\\raspberrypi\MyMedia-Write(full access)
- Finder →
Cmd+K - Enter:
smb://raspberrypi/MyMedia(guest) orsmb://raspberrypi/MyMedia-Write(authenticated) - Select Guest or enter your username/password
Troubleshooting: If hostname doesn't work, use IP address instead: \\192.168.1.X\MyMedia or smb://192.168.1.X/MyMedia
Find your Pi's IP with: hostname -I
Samba: Open-source implementation of SMB/CIFS file sharing protocol (Windows-compatible)
Guest Access: Passwordless, read-only access for casual viewing
Force User: Makes guests act as your user for file permissions (but Samba still prevents writing)
Valid Users: Restricts share access to specific authenticated users
- Add more drives and create separate shares
- Set up automatic backups with
rsync - Configure static IP address for easier access
- Add time machine support for Mac backups
Important: This setup isn't RAID-protected. Always backup critical data elsewhere!
# Find Pi IP address
hostname -I
# Check drive status
df -h
# View Samba logs
sudo tail -f /var/log/samba/log.smbd
# Restart Samba after changes
sudo systemctl restart smbd nmbd
# Test configuration
testparm -s