Raspberry Pi NAS

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.

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.

  1. Bring up the Raspberry Pi terminal either by SSH or on the Pi itself.
  2. First let’s bring Raspbian up to date by entering the following commands:
sudo apt-get update
sudo apt-get upgrade
  1. We will want to install ntfs support so let’s first install the package.
    sudo apt-get install ntfs-3g
  2. Next we want to find our external hard drive to do this enter the following command.
    sudo fdisk -l
  3. 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 Rasbpain is currently running on (Should be something like /dev/mcbblkop1) ignore this one.There should also be another one that looks similar to /dev/sda1 this is the drive that we will use.
    fdisk command
  4. 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
  5. 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
  6. You will be prompted to enter a password twice, be sure to remember this password as you may need it later on.
  7. 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
  8. 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
  9. Add the following the line to the bottom of the file. Changing the /dev/sda1 to 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


  10. 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.

  1. First we will need to install the samba package by entering the following command:
sudo apt-get install samba samba-common-bin
  1. 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
  2. Now let’s edit the config file by entering the following:
    sudo nano /etc/samba/smb.conf
  3. There are several edits we will need to make to this file, first remove the # from the security = user line.
    Security User
  4. 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):
    comment = NAS Folder
    path = /media/NASHDD1
    valid users = @users
    force group = users
    create mask = 0660
    directory mask = 0771
    read only = no
  5. 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.
  6. Now restart the samba server by entering the following command:
    sudo /etc/init.d/samba restart
  7. 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.

  1. On a windows PC open up file explorer.
  2. Click on network in the left hand column.
  3. In here open up Raspberry Pi.
  4. Double click on the folder.
  5. Enter the credentials.
  6. You should now be able to save, edit and delete files in this folder.

How to Map network drives


If you have a Mac please do the following to gain access to the NAS.

  1. Click on go in the top bar and navigate to connect to server.
  2. In here add the IP address of the Pi or browse to the Raspberry Pi. (You will need to specify the folder)
  3. Enter your credentials.
  4. You should now be able to save, edit and delete files within this folder.

Map Network Drives Mac

The Raspberry Pi Crash Course

The Raspberry Pi Crash Course

Enter your email address below to get the

Raspberry Pi crash course delivered straight to your inbox

Please check your inbox for a confirmation email!