Before we download anything, we need to start with a fresh update. In this guide, I'm using a Raspberry 3 B+ with Raspbian installed. Be sure to update your OS to the latest version. Visit our guide here on how to update to the latest version of Raspbian.
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:
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
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.
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:
Change the read only section to reflect:
read only = no
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
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:
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
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:
Private folder access (for a user named pi):
If you don't want to go the Samba route, there are two applications worth mentioning, and both are relatively simple to install.
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!