How to Build a Raspberry Pi NAS Using Samba

Your network storage just got bigger!
Ash Ash (362)
30 minutes

Setting up your own network storage device is super easy with a Raspberry Pi. All you need is an application called Samba and a few tweaks to the default settings. Before you know it, everyone on your network will have access to a custom Raspberry Pi NAS system. Everyone can share files with each other or even keep a private network folder for themselves.

If you're looking for something a little less technically-involved, skip to the end where we'll discuss OpenMediaVault and NAS4Free.

Raspberry PiRaspberry Pi ×1

Howchoo is reader-supported. As an Amazon Associate, we may earn a small affiliate commission at no cost to you when you buy through our links.

Update Raspberry Pi OS

Before we download anything, we need to start with a fresh update. In this guide, I'm using a Raspberry 3 B+ with Raspberry Pi OS (formerly Raspbian) installed. Be sure to update your OS to the latest version. Visit our guide on how to update to the latest version of Raspberry Pi OS.

Once everything is up to date, it might be a good idea to restart your Raspberry Pi. You can use the following command to restart:

sudo reboot

After a fresh update and restart, we're ready to get started. Run the following command to install Samba on your Pi.

sudo apt install samba samba-common-bin

Samba will need a place to store our files on the network. Therefor we will create our own directories and point Samba to them. Use the following commands to create both a private and public directory location.

Note: My example places the folders under the /home/ directory. You may find another location is suitable for your NAS structure.

sudo mkdir /home/storage
sudo mkdir /home/storage/public

These directories require special permissions to function properly. Use the following commands to set the permissions.

sudo chown -R root:users /home/storage/public
sudo chmod -R ug=rwx,o=rx /home/storage/public
Enable authentication prompt

If you want to enable a login prompt for your storage device, open the following file.

sudo nano /etc/samba/smb.conf

Look for this line:

##### Authentication #####

Beneath it, add the following string:

security = user

Leave this file open, we will be using it for the next couple of steps.

Adjust private storage permissions

This step will allow for write permissions to the private storage directory. Using the same file from the previous step, look for a section titled:

[homes]

Change the read only section to reflect:

read only = no
Adjust public storage permissions

This step will set access permissions for the public storage directory. Using the same file from the previous steps, scroll to very bottom and enter the following:

[public] 
comment = public storage 
path = /home/storage/public 
valid users = @users 
force group = users 
create mask = 0660 
directory mask = 0771 
read only = no

After adjusting all of the permission settings, we will need to save this file. Press ctrl + x to open the exit prompt. When asked to save the document, press Y and enter.

Restart Samba with the following command:

sudo /etc/init.d/samba restart

If you'd like to add a user to Samba, run the following command:

sudo smbpasswd -a pi

In my example, I'm adding the user "Pi". Follow the prompts from Samba to set a password for the NAS.

You can provide extra storage to your NAS device by adding a usb thumbdrive or even harddrive. Plug in the device and use the following command to find its name:

dmesg

If this is the first and only usb storage device, it will probably be named "sda1". Whichever device you'd like to add to the NAS, take note of the name.

Format the drive

If you haven't already, you will need to format the drive with a Linux file system. Use the following code to format the drive, replacing "sda1" with the appropriate drive name.

umount /dev/sda1
sudo mkfs.ext4 /dev/sda1

Create a directory for the additional drive

Create a directory for the drive and set appropriate permissions with the following code:

sudo mkdir /home/storage/public/disk1
sudo chown -R root:users /home/storage/public/disk1
sudo chmod -R ug=rwx,o=rx /home/storage/public/dis

Enable drive mount on reboot

Rebooting your Pi will cause the drive to dismount. You can set up the pi to always mount the additional device on startup. Run the following command:

sudo nano /etc/fstab

Add the following line to the bottom of the file for each drive you want to mount. Replace "sda1" with the name of the respective drive.

/dev/sda1 /home/storage/public/disk1 auto noatime,nofail 0 0
Connect to the NAS

This is the easiest part. Congratulations! Your NAS Pi device should now be accessible on your network. It's time to drag and drop files to your heart's content. If you're using a Windows device, the following path will open the NAS from a run window.

Note: My Pi is named "raspberrypi". You will need to adjust the example to reflect the name of your Pi.

Public folder access:

\\raspberrypi\public

Private folder access (for a user named pi):

\\raspberrypi\pi

If you don't want to go the Samba route, there are two applications worth mentioning, and both are relatively simple to install.

OpenMediaVault and NAS4Free are available for free, and they install easily from a disk image.

Download the image for either, then write the image to your SD card. I'd recommend checking out Etcher to do this, since it's available for Windows/Mac/Linux and simple to use.

Pop that SD card into your Raspberry Pi and watch as they install automatically. Finish configuring with your IP address and voila!

Find the best method for your project.
Ash Ash (362)
5 minutes

Some Pi operating systems come with specific instructions for transferring files—like RetroPie. However, I'll assume your Pi is running Raspberry Pi OS (formerly Raspbian).