How to Build a NAS Server with Raspberry Pi And Samba
A network-attached storage machine (NAS) allows you to access documents over your stretch network, and also you can construct one inexpensively with a Raspberry Pi. Immaculate of all, the arrangement strategy is less facility than you might reckon, and also I’m here to overview you wearing it.
- What You’ll Call for
- Placement Upward Samba
- Access your NAS from Residence windows
- Access your NAS from macOS
- Fixing prevalent NAS hassles
What You’ll Call for
Let’s congregate all the obligatory parts before we prelude. Evidently, you’ll final notification a Raspberry Pi. The Pi 5 or Pi 4 are unblemished for sooner documents transmits, yet Pi 3 works also. You’ll in addition final notification a microSD card (32 GB minimum) with totally modernized Raspberry Pi OS.

While you can practically intake the SD card for documents storage objectives, it’s a boatload much more described to buy an external storage machine. Spinning difficult drives are ideal for long-term documents archiving, yet you can in addition intake an external SSD or also a USB flash drive.
If you’re pensive about information protection, you might stab to ponder gaining use of numerous drives in a RAID arrangement that rivaling your information across drives to safeguard it versus drive scarcity of abilities. For a boatload more info, you can refer to our overview on RAID.
Placement Upward Samba
1. Preparation your storage
First, you have to drifter your storage machine so that you can intake it to store the information you stab to be obtainable over your stretch network.
If you’re forming a folder on your mechanism SD card (which I don’t prescribe), you can merely sprinted the subsequent command to symptom a magazine:
mkdir /home/pi/nas-storage
To intake an external drive (the advised ideology), you have to layout it with a unblemished documents mechanism. I highly prescribe ext4 for the ideal possible compatibility with Linux. Fire upward your incurable and also sprinted:
sudo fdisk -l
Perfection wearing the result and also detect the drive you stab to intake for your NAS (it will distinctly numerous likely be “sda” or “sda1”, yet it can in addition be “sdb” or “sdb1” if you have numerous drives bridged). As rapidly as you’ve certified the right drive, render a mental note of its tag – you’ll final notification it for the next off command, which unmounts the drive so that you can layout it (replace “NAME” with everything you detected in the result of the command overhanging):
sudo umount /dev/NAME
Now it’s format time. The subsequent command will distinctly glean rid of all information on the drive, so twin-discover you’re gaining use of the rectify machine. As rapidly as you’re ready, you can go into (render sure to adjustment “NAME” with the machine tag that you rendered a note of earlier):
sudo mkfs -t ext4 /dev/NAME
After format, you might stab to label your drive for less facility reference later:
sudo e2label /dev/NAME YOURLABEL
Replace “NAME” with your drive’s identifier and also “YOURLABEL” with your favored label. Now let’s install the drive so we can intake it:
sudo mkdir -p /mnt/nas-storage sudo mount /dev/NAME /mnt/nas-storage
After that, it’s a good proposal to reboot, so go onward and also go into:
sudo reboot
2. Void Samba
Now that our storage is ready, we final notification a means for different other equipments to access it over the network. This is wherein Samba comes in. It’s a fanciful hunk of software masterstroke that allows documents sharing between Linux and also Residence windows equipments (and also yes, Macs also!).
I designate gaining use of Samba because it’s praiseworthy and also can be mounted with a single command:
sudo apt install samba samba-common-bin

The command will distinctly download and also install everything you final notification for straightforward documents sharing. As rapidly as installment coatings, Samba will distinctly conveniently prelude running as a solution in the history, yet we’re not rather done yet because we still have to configure it to intake the storage machine we planned in shifting 1.
3. Configure Samba
Now we have to tell Samba what we stab to share on our network by editing its arrangement documents. You can access the Samba arrangement documents by running:
sudo nano /etc/samba/smb.conf
As rapidly as you’re in, scroll down to the bottom and also contain a couple of added spiels to tell Samba what you stab to share. It have to filter something designate this:
[sambadrive] path = /mnt/nas-storage writeable=Yes read only=no create mask=0777 directory mask=0777 public=no

Here’s what each placement carries out:
[sambadrive]
is the tag of our NAS that different other equipments will distinctly appointment on the network.path
points to wherein we mounted our drive.writeable = yes
allows borrowers to adjustment documents.create mask
and alsodirectory mask
package documents assents.public = no
supposes borrowers final notification a password to connect.browseable = yes
makes the share identifiable in network internet browsers.
Through that, you’re done with the config documents! Hit Ctrl + O and also Get in to conserve (merely to be hazard-emancipate!), after that Ctrl + X to chummy the documents.
4. Design a Samba borrower
Next, you’ll have to render a Samba username/password. The default Raspberry Pi borrower is merely termed “pi,” so that’s an straightforward one to go with. Get in the subsequent command:
sudo smbpasswd -a pi
This will distinctly symptom a Samba borrower termed “pi” with a password. You’ll buy a quick to go into a password. Kind it in, hit Get in, and also execute it once again.

Next, restart Samba to buildings the amendments gaining use of:
sudo systemctl restart smbd
You’re all done with the arrangement! Now, you can access your NAS from a unalike machine.
Access your NAS from Residence windows
Now comes the enjoyable space – securing to your brand name-distinguished NAS from Residence windows. Open File Trekker and also filter for the “Map Network Drive” switch. In more current Residence windows versions, you’ll detect it under the “Computer” tab when you’re in “This PC”, or it might be classified as “Map as Drive” under “Straightforward Access” in different other folders.

Clicking this opens upward a arrangement dialog wherein you’ll have to go into your Pi’s network address. Kind \raspberrypinas-share
in the Folder box (remember, “nas-share” is what we termed our share in the Samba config). You can in addition intake your Pi’s IP address instead of “raspberrypi” if you’re owning issue securing.

Render sure to discover the “Affix gaining use of unalike certifications” box, after that click Coating. Residence windows will distinctly ask for your username and also password – these are the Samba certifications we stimulated earlier (username “pi” and also the password you package).

Your NAS drive have to presently show up in File Trekker, ready for you to prelude conserving and also accessing documents over your network.
Access your NAS from macOS
Affixing to your NAS from a Mac is merely as straightforward as Residence windows. In the majority of instances, you can merely pick it from the left sidebar.
If you can appointment it in the left sidebar, after that you can amenable Finder and also press Cmd + K, or click “Go” in the sustenance selection pub and also pick “Affix to Server.” In the “Server Address” arena, kind smb://raspberrypi/nas-share
(or intake your Pi’s IP address instead of “raspberrypi” if needed). Click “Affix” when you’re ready.

A login dwelling window will distinctly pop upward. Pick “Enlisted Visitor,” go into “pi” as the username (or everything your username is) and also the Samba password you stimulated earlier. Review “Bear in mind this password in my keychain” if you don’t stab to go into it every time. You can presently drag and also downtrend documents merely designate any different other folder on your Mac.
Fixing prevalent NAS hassles
Designing a NAS with Samba on a Raspberry Pi is traditionally issue-emancipate, yet you might experience a couple of prevalent hassles. Here’s how to solve them right away and also buy endorse to gaining use of your NAS.
Access refuted or authorization disadvantageous moves
If you’re striking wall surfaces when trying to access or comprise to your prevalent folders, it’s in some instances because your Pi borrower doesn’t have the proper residential. To reconcile this:
sudo chown -R pi /mnt/nas-storage
Replace “pi” with your username if it’s unalike, and also “/mnt/nas-storage” with the route to your NAS folder. This command confers the Pi borrower residential over the entire magazine, which have to heal numerous authorization hassles.
NAS share not identifiable
If your NAS doesn’t show up in Residence windows File Trekker or macOS Finder, there can be a couple of unalike substantiations why. First, twin-discover that both your Raspberry Pi and also your computer are on the really same network. If they’re bridged to unalike Wi-Fi networks or gaining use of unalike network adapters, they won’t appointment each different other.
2nd, render sure that the Samba solution is literally running on your Raspberry Pi. You can discover by running the subsequent command:
sudo systemctl status smbd
If it’s not running (you will distinctly appointment an sluggish prestige), prelude it upward with this command:
sudo systemctl start smbd
Relationship keeps shedding
One of the a boatload more frustrating hassles you might experience with your Raspberry Pi NAS is the relationship shedding, particularly when it’s bridged wearing Wi-Fi. This can introduce as periodic access to your prevalent documents or the NAS becoming faultlessly unreachable for durations.
Oftentimes, this top priority arises due to Wi-Fi signal hassles or interference from different other equipments. However, if you’ve attested that your Wi-Fi network itself isn’t the offender, the issue might be relevant to the Raspberry Pi’s power-conserving amenities.
You appointment, the Pi’s Wi-Fi can go into power-conserving mode, which sporadically leads to these correlation depreciates, particularly if it’s not proactively transmitting or receiving information. Fortunately, you can comfortably disable this power-conserving feature. With one voice you have to execute is contain one queue to your “/etc/rc.stretch” documents:
/sbin/iwconfig wlan0 power off
As you can appointment, also alarming hassles with Samba are reasonably straightforward to troubleshoot and also heal, which is merely one a boatload more determinant why it’s so good for straightforward documents sharing. However if you’re glimpsing for a boatload more proceeded amenities designate borrower handling, booked fallbacks, or a internet interface might stab to discover out OpenMediaVault.
Photograph credit ratings: Raspberry 4 Model B Screenshots by Andrew Braun and also David Morelo.