A Raspberry Pi NAS or network attached storage is the perfect way to have files available to anyone within your local network. It is a relatively easy process to set this up and being low powered allows for it to be on 24/7 without costing you a fortune in power bills.
Once you have setup your first drive correctly you will find this process to be incredibly easy to repeat. You may come across some complications when first setting it up these problems are usually caused by having the permissions set incorrectly.
One other thing that I should mention is that if you’re looking for blazing fast speeds then you’re unlikely to get them with the Pi. This is due to having to use the USB ports (2.0) to connect a hard drive and the network interfaces. (100 mbps Ethernet or WiFi)
Check out the video below to see how to setup your very own NAS in no time. If you like what you see then please subscribe so you stay up to date on all the latest guides, projects and much more.
I used the following equipment for this Raspberry Pi NAS tutorial.
Note: The USB ports on the Raspberry Pi might not be enough to power an external drive so you might need to invest in a powered USB hub.
Setting up the Raspberry Pi NAS
In this tutorial I use the standard operating system for the Raspberry Pi. This is Raspbian, if you would like to install it then check out my guide on how to install Raspberry Pi NOOBS.
Mounting The Hard drives
The first thing before we setup the NAS is mount the external hard drives. This is important that we do this correctly the first time otherwise we could end up with issues later on. You want to be able to mount a drive so it will always be the same even if the Pi loses power or reboots.
- Bring up the Raspberry Pi terminal either by using SSH or on the Pi itself.
- First let’s bring Raspbian up to date by entering the following commands:
sudo apt-get update sudo apt-get upgrade
- We will want to install ntfs support so let’s first install the package.
sudo apt-get install ntfs-3g
- Next we want to find our external hard drive to do this enter the following command.
sudo fdisk -l
- There should be two lots of drives that pop up unless you have more than 1 drive connected. The first would be the SD card that Raspbian is currently running on (Should be something like
/dev/mcbblkop1) ignore this one.There should also be another one that looks similar to
/dev/sda1this is the drive that we will use.
- Before we mount the drives we will need to create a directory to mount to. To do this enter the following command. (Remember to fix up the command with the correct drive name)
sudo mkdir /media/NASHDD1
- Now before we continue we will need to create a user to login as. To do this enter the following. Note: Update the word pimylifeup to change the user name.
sudo useradd pimylifeup -m -G users sudo passwd pimylifeup
- You will be prompted to enter a password twice, be sure to remember this password as you may need it later on.
- Next we need to get the gid and the uid, make sure you write these down as we will need them in the next step. Update pimylifeup with the user you created above.
For the gid enter the following:
id -g pimylifeup
For the uid enter the following:
id -u pimylifeup
- Now we need to edit the fstab file so our Pi will automatically mount the drive on boot up and set the correct permissions, to do this enter the following command:
sudo nano /etc/fstab
- Add the following the line to the bottom of the file. Changing the
/dev/sda1to whatever your hard drive is and updating uid and gid as appropriate. (The code below is all one line)
/dev/sda1 /media/NASHDD1 auto nofail,uid=enter_uid_here,gid=enter_gid_here,noatime 0 0
- Reboot the Raspberry Pi and the drives should automatically mount with the correct permissions.
Now that we have completed mounting the drives to the folders we can now move onto setting up the samba server. If you wish to make edits to the folder do the changes into the mounted folder. For example if we wanted to make a new directory we would enter the following.
sudo mkdir /media/NASHDD1/share
Setting up the Raspberry Pi Samba Server
In this part we will download and install the samba package so we can have a Raspberry Pi samba server up and going. If you want more information on the package and it’s documentation you can check out the Samba website.
- First we will need to install the samba package by entering the following command:
sudo apt-get install samba samba-common-bin
- Just in case we make any mistakes along the way we should back up the samba config folder. To do this enter the following command:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
- Now let’s edit the config file by entering the following:
sudo nano /etc/samba/smb.conf
- There are several edits we will need to make to this file, first remove the # from the
security = userline.
- Next we will need to add our hard drive to the samba config file. Enter the following to add your hard drive as a share (Update the path if you have something different):
[NAS] comment = NAS Folder path = /media/NASHDD1 valid users = @users force group = users create mask = 0660 directory mask = 0771 read only = no
- I’ll quickly explain what each of the things mean above so you have a better understanding the Raspberry Pi Samba Server.
- [NAS]: This is the name of the share (What you will see in file explorer)
- Comment: This is a comment for the associated for share.
- Path: Path to the folder you wish to share.
- Valid User: A list of users that are allowed to login to this share.
- Force Group: This specifies a UNIX group name that will be assigned for all users connecting to this share.
- Directory Mask: This creates a permission mask for all directories created on the drive.
- Read Only: This allows you to set the share to be read only.
- Now restart the samba server by entering the following command:
sudo /etc/init.d/samba restart
- Finally you will need to connect the user to samba do this by entering the following:
sudo smbpasswd -a pimylifeup
Testing the Raspberry Pi NAS
Now we have it all setup we will need to test to make sure everything is configured properly. This is very easy to test so I will go through an example of both Windows and Mac.
Once you have done this test you should now have a full working Raspberry Pi Samba Server. Be sure to check out the many other Raspberry Pi projects and guides we have on here. Have troubles or improvements to this tutorial leave us a comment below!
If you have a windows PC please do the following to access the Raspberry Pi NAS.
- On a windows PC open up file explorer.
- Click on network in the left hand column.
- In here open up Raspberry Pi.
- Double click on the folder.
- Enter the credentials.
- You should now be able to save, edit and delete files in this folder.
If you have a Mac please do the following to gain access to the NAS.
- Click on go in the top bar and navigate to connect to server.
- In here add the IP address of the Pi or browse to the Raspberry Pi. (You will need to specify the folder)
- Enter your credentials.
- You should now be able to save, edit and delete files within this folder.
I hope that you now have the Raspberry Pi NAS up and running without any issues. If you do come across any problems or have questions then be sure to leave a comment below.