0
0
Iot-protocolsHow-ToBeginner · 4 min read

How to Set Up Raspberry Pi as NAS: Simple Step-by-Step Guide

To set up a Raspberry Pi as a NAS, install and configure Samba to share files over your local network. Connect an external drive or use the Pi's storage, then create shared folders with proper permissions using smb.conf.
📐

Syntax

Here is the basic syntax to install and configure Samba on Raspberry Pi:

  • sudo apt update - Updates the package list.
  • sudo apt install samba samba-common-bin - Installs Samba server and tools.
  • sudo nano /etc/samba/smb.conf - Opens Samba configuration file to define shared folders.
  • sudo systemctl restart smbd - Restarts Samba service to apply changes.

In smb.conf, you add a section like:

[SharedFolder]
   path = /path/to/folder
   browseable = yes
   writeable = yes
   guest ok = no
   create mask = 0777
   directory mask = 0777
   public = yes

This defines a shared folder accessible on the network.

bash
sudo apt update
sudo apt install samba samba-common-bin
sudo nano /etc/samba/smb.conf
# Add shared folder config
sudo systemctl restart smbd
💻

Example

This example shows how to share a folder named nas_share located on an external USB drive mounted at /mnt/usb.

Steps:

  • Create the folder: sudo mkdir -p /mnt/usb/nas_share
  • Change permissions: sudo chmod -R 777 /mnt/usb/nas_share
  • Edit Samba config to add:
[nas_share]
   path = /mnt/usb/nas_share
   browseable = yes
   writeable = yes
   guest ok = yes
   create mask = 0777
   directory mask = 0777

Restart Samba and access the share from another computer on the network.

bash
sudo mkdir -p /mnt/usb/nas_share
sudo chmod -R 777 /mnt/usb/nas_share
sudo nano /etc/samba/smb.conf
# Add the following at the end:
# [nas_share]
# path = /mnt/usb/nas_share
# browseable = yes
# writeable = yes
# guest ok = yes
# create mask = 0777
# directory mask = 0777
sudo systemctl restart smbd
⚠️

Common Pitfalls

Common mistakes when setting up Raspberry Pi as NAS include:

  • Not setting correct folder permissions, causing access denied errors.
  • Forgetting to restart Samba after config changes, so shares don't update.
  • Using guest ok = no without setting up Samba users, blocking access.
  • Not mounting external drives automatically, so shares disappear after reboot.

Always test access from another device after setup.

ini
Wrong config example:
[nas_share]
   path = /mnt/usb/nas_share
   browseable = yes
   writeable = yes
   guest ok = no

Right config example:
[nas_share]
   path = /mnt/usb/nas_share
   browseable = yes
   writeable = yes
   guest ok = yes
📊

Quick Reference

StepCommand/ActionPurpose
1sudo apt updateUpdate package list
2sudo apt install samba samba-common-binInstall Samba server
3sudo mkdir -p /mnt/usb/nas_shareCreate shared folder
4sudo chmod -R 777 /mnt/usb/nas_shareSet folder permissions
5Edit /etc/samba/smb.confAdd share configuration
6sudo systemctl restart smbdRestart Samba service
7Access share from networkUse file explorer or \\raspberrypi\nas_share

Key Takeaways

Install Samba to enable file sharing on Raspberry Pi.
Configure shared folders in /etc/samba/smb.conf with correct permissions.
Restart Samba service after any configuration changes.
Ensure external drives are mounted and accessible before sharing.
Test network access from another device to confirm setup.