Setting up a NAS with Raspberry Pi

  • 2nd Aug 2024
  • 1 min read

📝 From my notes: living personal cheatsheets.

1. Install Samba

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

2. Mount Storage Drive

sudo mkdir -p /mnt/nas
sudo mount /dev/sda2 /mnt/nas
df -h  # Verify mount

3. Configure Automatic Mounting

Edit the fstab file:

sudo $EDITOR /etc/fstab

Add this line:

WARNING

Replace the uid and gid with your user’s. You can find these values by running id -u and id -g.

/dev/sda2  /mnt/nas  exfat  defaults,auto,nofail,umask=000,dmask=000,fmask=000,uid=1000,gid=1000  0  0

Apply changes:

sudo mount -a

4. Configure Samba

Edit Samba configuration:

sudo $EDITOR /etc/samba/smb.conf

Add this section:

TIP

Replace your_username with your actual Raspberry Pi username in the following configuration.

[NAS]
    path = /mnt/nas
    writeable = yes
    create mask = 0777
    directory mask = 0777
    force user = your_username
    force group = your_username
    public = no
DANGER

These permissions (0777) grant full access to all users. Consider reading about Linux file permissions.

5. Create Samba User

sudo smbpasswd -a your_username

6. Restart Services and Configure Firewall

sudo systemctl restart smbd
sudo ufw allow samba

7. Connect from macOS

  1. In Finder, select Go > Connect to Server
  2. Enter: smb://your_pi_ip/NAS
  3. Enter your Samba credentials

8. Optional: Add to Finder Sidebar

Drag the mounted NAS icon to your Finder sidebar for quick access