DEV Community

Cover image for Turn Your Home Server into a NAS — Access Files from Any Device with Samba
Sasanka Rath
Sasanka Rath

Posted on

Turn Your Home Server into a NAS — Access Files from Any Device with Samba

In Part 2, we set up Nextcloud with Docker — your own Google Drive with phone auto-backup and desktop sync. That handles cloud-style access perfectly.

But sometimes you just want to drag files into a folder. No browser, no app, no sync client — just open Finder on your Mac (or File Explorer on Windows), and there's your server, looking like any other drive.

That's what Samba does. It turns your home server into a NAS (Network Attached Storage) that any device on your network can access natively.

What you'll have after this guide:

  • Your server's folders visible in Mac Finder / Windows File Explorer
  • Drag-and-drop file transfer at full network speed
  • Auto-mount on startup so the drive is always there
  • Nextcloud and Samba sharing the same storage — files added via either method are visible in both
  • Remote NAS access via Tailscale (set up in Part 4)

Let's set it up.


How Samba and Nextcloud work together

This is important to understand before we start. Both Nextcloud and Samba will point to the same storage directory (/srv/nas). This means:

  • Upload a photo via Nextcloud's web interface → it appears in Samba immediately
  • Drop a video into the Samba share from your Mac → Nextcloud can see it after a quick scan

They're two doors into the same room. Nextcloud gives you the cloud experience (browser, apps, sharing links). Samba gives you the local network experience (Finder, drag-and-drop, raw speed).

💡 When you add files via Samba, Nextcloud won't detect them automatically. You'll need to run a quick scan command. I'll cover this at the end.


Step 1: Install Samba

SSH into your server and install Samba:

sudo apt install samba -y
Enter fullscreen mode Exit fullscreen mode

Verify it's installed:

smbd --version
Enter fullscreen mode Exit fullscreen mode

You should see something like Version 4.x.x. Samba is now installed but not configured yet.


Step 2: Create a Samba password

Samba uses its own password system, separate from your Linux login. Create a Samba password for your user:

sudo smbpasswd -a your-username
Enter fullscreen mode Exit fullscreen mode

Replace your-username with your actual Linux username. It'll ask you to set a password — this is what you'll enter when connecting from your Mac or PC. It can be different from your Linux password.


Step 3: Configure Samba shares

Open the Samba config file:

sudo nano /etc/samba/smb.conf
Enter fullscreen mode Exit fullscreen mode

Scroll to the bottom and add your shared folders:

[NAS]
   path = /srv/nas
   browseable = yes
   read only = no
   valid users = your-username
   create mask = 0644
   directory mask = 0755
   force user = www-data
   force group = www-data

[Photos]
   path = /srv/nas/photos
   browseable = yes
   read only = no
   valid users = your-username
   create mask = 0644
   directory mask = 0755
   force user = www-data
   force group = www-data

[Videos]
   path = /srv/nas/videos
   browseable = yes
   read only = no
   valid users = your-username
   create mask = 0644
   directory mask = 0755
   force user = www-data
   force group = www-data
Enter fullscreen mode Exit fullscreen mode

Let me explain the key settings:

  • path — the directory to share
  • browseable = yes — makes it visible when browsing the network
  • read only = no — allows writing (uploading files)
  • valid users — only this user can access the share
  • force user / force group = www-data — this is critical. Nextcloud runs as www-data, so any file created via Samba must also be owned by www-data. Without this, Nextcloud can't read files you add through Samba.

Save and exit (Ctrl+X, then Y, then Enter).


Step 4: Set permissions

Make sure the storage directory has the right ownership:

sudo chown -R www-data:www-data /srv/nas
sudo chmod -R 775 /srv/nas
Enter fullscreen mode Exit fullscreen mode

This ensures both Nextcloud (running as www-data) and Samba can read and write to the same files without permission conflicts.


Step 5: Restart Samba

sudo systemctl restart smbd
sudo systemctl enable smbd
Enter fullscreen mode Exit fullscreen mode

The enable command ensures Samba starts automatically after reboots.

Verify it's running:

sudo systemctl status smbd
Enter fullscreen mode Exit fullscreen mode

You should see active (running) in green.


Step 6: Open firewall ports

If you're running UFW (which you should be — we'll set it up properly in Part 5), allow Samba traffic:

sudo ufw allow 137/udp
sudo ufw allow 138/udp
sudo ufw allow 139/tcp
sudo ufw allow 445/tcp
Enter fullscreen mode Exit fullscreen mode

These are the standard ports Samba uses for NetBIOS and file sharing.


Step 7: Connect from Mac

  1. Open Finder
  2. Press Cmd+K (or click Go → Connect to Server)
  3. Type: smb://192.168.1.100 (replace with your server's IP)
  4. Click Connect
  5. Select Registered User
  6. Enter your username and the Samba password you created in Step 2
  7. Select which shares to mount: NAS, Photos, Videos
  8. Click OK

Your server's folders now appear in the Finder sidebar under "Locations." You can drag files in, open them directly, and treat it exactly like a USB drive — except it's over your network.

Auto-mount on Mac startup

So you don't have to reconnect every time:

  1. Connect to the NAS using the steps above
  2. Go to System Settings → General → Login Items
  3. Click + under "Open at Login"
  4. Navigate to Network → your server IP → select the NAS folder
  5. The drive now mounts automatically every time your Mac starts

Step 8: Connect from Windows

  1. Open File Explorer
  2. Click the address bar at the top
  3. Type: \\192.168.1.100 (backslashes, not forward slashes)
  4. Press Enter
  5. Enter your username and Samba password
  6. Check "Remember my credentials" if you want auto-login
  7. Your shares appear as network folders

Map as a network drive (auto-mount):

  1. Right-click on the share folder
  2. Click Map network drive
  3. Choose a drive letter (e.g., Z:)
  4. Check Reconnect at sign-in
  5. Click Finish

Your server now shows up as Drive Z: in File Explorer, permanently.


Step 9: Sync Samba files with Nextcloud

When you add files through Samba (drag-and-drop from Mac/PC), Nextcloud doesn't know about them yet. You need to tell Nextcloud to scan for new files:

docker exec -u www-data nextcloud php occ files:scan --all
Enter fullscreen mode Exit fullscreen mode

This scans the entire storage directory and adds any new files to Nextcloud's index. Takes a few seconds for small changes, longer for thousands of files.

Make it automatic

If you're regularly adding files via Samba, set up a cron job to scan every 15 minutes:

crontab -e
Enter fullscreen mode Exit fullscreen mode

Add this line:

*/15 * * * * docker exec -u www-data nextcloud php occ files:scan --all > /dev/null 2>&1
Enter fullscreen mode Exit fullscreen mode

Now Nextcloud automatically picks up any files you add through Samba within 15 minutes.


Step 10: Bulk transfer — the fastest way to load your server

If you have hundreds of gigabytes of photos and videos to move onto your server, Samba is by far the fastest method. Here's the recommended approach:

  1. Connect via Samba from your Mac or PC (Steps 7 or 8)
  2. Drag and drop your files into the appropriate folders (photos → Photos, videos → Videos)
  3. Wait for transfer to complete — local network transfers are fast, typically 50-100 MB/s over WiFi, faster over Ethernet
  4. Run the Nextcloud scan once the transfer is done:
docker exec -u www-data nextcloud php occ files:scan --all
Enter fullscreen mode Exit fullscreen mode

This is much faster than uploading through Nextcloud's web interface, which has overhead from HTTP and PHP processing.

💡 Transferring a large collection? Use an Ethernet cable for the transfer if possible — you'll see 2-3x faster speeds compared to WiFi. A Cat 6 Ethernet cable costs practically nothing and makes a big difference for bulk transfers.


Troubleshooting

Can't see the server in Finder/File Explorer?

  • Make sure you're on the same WiFi network as the server
  • Try connecting directly via IP: smb://192.168.1.100 (Mac) or \\192.168.1.100 (Windows)
  • Check Samba is running: sudo systemctl status smbd

"Permission denied" when writing files?

  • Check ownership: ls -la /srv/nas/ — files should be owned by www-data
  • Fix permissions: sudo chown -R www-data:www-data /srv/nas
  • Make sure your smb.conf has force user = www-data

Files added via Samba not showing in Nextcloud?

  • Run the scan: docker exec -u www-data nextcloud php occ files:scan --all
  • Or wait for the cron job if you set one up

Connection drops after Mac sleep?

  • This is normal. The Mac disconnects SMB shares when it sleeps. It should auto-reconnect when it wakes up if you set up auto-mount (Step 7). If not, just press Cmd+K and reconnect.

Slow transfer speeds?

  • Switch to a wired connection. WiFi has overhead and interference. An Ethernet connection will give you significantly faster and more reliable transfers.

What you should have now

After following this guide:

✅ Samba installed and configured with NAS, Photos, and Videos shares
✅ Mac or Windows PC sees your server as a network drive
✅ Drag-and-drop file transfer at full network speed
✅ Auto-mount on startup so the drive is always there
✅ Nextcloud synced with Samba via manual scan or cron job
✅ A complete NAS setup using hardware you already own

Between Nextcloud (Part 2) and Samba (this guide), you now have two ways to access your files:

Method Best for Speed
Nextcloud (browser/app) Remote access, phone backup, sharing links Good
Samba (Finder/Explorer) Bulk transfers, local file access, drag-and-drop Fast

Use both. They complement each other perfectly.


What's next

Right now, everything works on your home network. But what about when you're not home?

🌐 Part 4: Access your server from anywhere — Set up Tailscale for private encrypted access, get an Oracle Free VPS, configure frp tunneling to bypass CGNAT, set up Nginx and SSL, and point your custom domain to your home server. After Part 4, you'll access your NAS from anywhere in the world.

🔒 Part 5: Security hardening + lessons learned — UFW firewall, Fail2Ban, SSH hardening, monitoring, and everything I wish I'd known before starting.

All config files from this series are available in the companion GitHub repo:
👉 github.com/sasrath/homecloud


Hit Follow if you don't want to miss Part 4 — that's the one where everything comes together. Drop a comment if you hit any issues with the Samba setup.

Your server is now a NAS. Next up: accessing it from anywhere in the world. 🌐

Top comments (0)