Pi My Life Up

Raspberry Pi NAS: Build a Raspberry Pi Samba Server

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 slowdown is due to having to use the USB ports (2.0) to connect a hard drive and the network interfaces. (100 Mbps Ethernet, 1 Gbps on Pi 3 B plus, 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.


Raspberry Pi

SD Card (8GB+ Recommended) or Micro SD Card if you’re using a Raspberry Pi 2, 3 or B+

Ethernet Cord or Wifi dongle

External Hard drive


Raspberry Pi Case

USB Keyboard

USB Mouse

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 (OS) for the Raspberry Pi. This OS 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 to do before we set up the NAS is to mount the external hard drives. For this step it 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 using 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

3. We will want to install ntfs support so let’s first install the package.

sudo apt-get install ntfs-3g

4. Next, we want to find our external hard drive to do this enter the following command.

sudo fdisk -l

5. There should be two lots of drives that pop up unless you have more than one 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/sda1 this is the drive that we will use.

6. Before we mount the drives, we will need to create a directory to mount. To do this enter the following command. (Remember to fix up the command with the correct drive name)

sudo mkdir /media/NASHDD1

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

sudo useradd pimylifeup -m -G users
sudo passwd pimylifeup

8. You will be prompted to enter a password twice, be sure to remember this password as you may need it later on.

9. Next, we need to get the gid and the uid, make sure you write these down as we will need these items 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

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

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

12. 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 in 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 running. If you want more information on the package and its 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

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

3. Now let’s edit the config file by entering the following:

sudo nano /etc/samba/smb.conf

4. There are several edits we will need to make to this file, first remove the # from the security = user line.

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

6. I’ll quickly explain what each of the things means above so you have a better understanding the Raspberry Pi Samba Server.

7. Now restart the samba server by entering the following command:

sudo /etc/init.d/samba restart

8. 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 set up we will need to test to make sure everything is configured properly. It 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.


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

1. Click on go, this is located in the top bar. Next, 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.

That’s it, and you should now be successfully connected to your NAS and be able to read and write files. If you’re having trouble with files copying to the drive, then it’s likely your permissions are incorrect, be sure to double check what you have entered.

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.


Dave on May 13th, 2015 at 4:38am

Hi There, I followed your guide, and i can see the folder being shared on my windows machine, but I can't create a file. It just says that I don't have the right permissions.

Gus on May 13th, 2015 at 1:23pm

Hi Dave,

I just noticed a slight mistake in the tutorial. Can you double check the uid and gid in the fstab file.

Replacing pimylifeup with your own user name the following will get you the uid

id -u pimylifeup

The following will get you the gid:

id -g pimylifeup

Peter on September 17th, 2016 at 8:03am

Gus, great build instructions, followed the build and once I connected to the PI drives from Windows and tried to create a test file, was blocked with a permissions issue, which I resolved via CHMOD, which might be overkill, any way I can write to the drives from Windows. But my biggest gotcha is this; I am using 2 identical thumb drives, 32gb each, but from Windows I can only see 9gb available, whereas within the PI I see 28.9gb, moving on I want to repeat the exercise using 1tb disks for a backup environment. Any suggestions? btw the disks were formatted as NTFS

Jonas Storm on June 13th, 2015 at 8:19am

Hey, I hope you can help me. I have followed your guide, change the user to Jonas and so on. The problem it that i cant access the folder from my windows computer. And thanks for the guide.

Gus on July 11th, 2015 at 1:42pm

Hey Jonas,

Sorry for a bit of a late reply.

Can you see the folder at all? Is there a particular error popping up ?

Please let me know, ill be happy to help you get it working.

Jay on June 16th, 2015 at 2:06am

Hi.. thanks for perfect tutorial. One question. A have raspbian + KODI. How to mount my hdd to see in kodi openELEC?

Jay on June 16th, 2015 at 3:54am

Maybe I didn't explain correctly. I did all according your tutorial and all work well.

But if I start OpenELEC_Pi2 I'm not able to see or add my HDD connected to raspberry.

Thanks for any update or help.

Barry Horne on July 6th, 2015 at 2:54am

Thanks for the tutorial. Having set up the NAS I can see it on my Windows machine but not on my Raspberry Pi 2 workstation. How do I see the NAS under Raspbian?


Gus on July 7th, 2015 at 6:19pm

Hey Barry,

If you open up file manager within the Raspbian GUI (Menu->Accessories->File Manager) and then got the top menu bar and select GO->Network. This will load up your network and the machine with the drive should be shown. If you double click on the machine it will ask for credentials and then login and your drive should be shown.

POPMUZIK on July 19th, 2015 at 9:03am

I found this command helped me see that "Drive" in Raspbian:
sudo mount -t auto /dev/sda1 /media/Name_of_Your_Drive

I did that command after the "sudo mkdir /media/NASHDD1" command during this tutorial.

Mark Epskamp on July 11th, 2015 at 9:02am

Hi i also cannot add folders or items to the shared folder. my mac tells me i have not the sufficient read rights??
UID and GID are correct.

Gus on July 11th, 2015 at 1:47pm

Hi Mark,

Can you please run the following.

ls - l /media/NASHDD1

Replacing NASHDD1 with the name you gave the folder.

It should come back as your user having permissions if not there may be an issue with the drive mounting. To check just double check the drive is at the right address (eg. /dev/sda1) and the fdisk line is correct (Make sure the drive is connected at boot up)

Let me know how you go and Ill be happy to help you further.

Michal on August 5th, 2015 at 11:56pm

Hi Gus,
I have a question. How fast can you access files from your windows computer? How fast can you copy to and from NAS?(One big file to make it easier)

Btw. really nice tutorial.

POPMUZIK on August 6th, 2015 at 4:56am

It's pretty much instant access from my Windows pc to my RPi nas. I am able to transfer data around 6-8 MBps (Megs per second) using my wireless N adaptor from my Windows to router. My RPi is hardwired/ network cable into my router for max speed. My data transfer speed is consistent whether it's a 50mb or 2gb file, hope this helps

Manuel on September 4th, 2015 at 5:56pm

Hi Gus!

I really appreaciate your tutorial. I will build it at home. Could you tell us something about the performance? I mean, transfer rates to other PCs and streaming 1080p files to the Raspberry Pi.
In addition, what about to format the HDD in ext4 system files?

WarHawk (Brian C) on August 23rd, 2017 at 6:15pm

100 Mb/s (mega bit/second or approx 12.5MB/s mega bytes/second) ethernet connection
No faster..due to the ethernet speed on the RPi

Pieter on September 4th, 2015 at 7:38pm


everything works just fine untill the command
"sudo /etc/init.d/samba restart"
now I'm totaly stuck, some suggestions?


Gus on September 12th, 2015 at 11:24am

Hi Pieter,

Are you getting any errors when you run that command?

Doan on September 10th, 2015 at 5:55am

Hi there, thanks for your guide! I set it up and everything seems to work. However, after creating several folders (like [NAS]) in Samba it seems everything I create in one folder gets copied to the others. I am trying to set up one shared folder and one folder for each person on my network. Is this possible?

Gus on September 12th, 2015 at 11:23am

Hi Doan,

In order create independent folders for each user in the Raspberry Pi NAS you need to change the following lines in our folder setup: (replace with the unix username.

valid users = @users
valid users =

If you're not already doing for each [] folder you create you need to specify a new folder.. I recommended something like:

path = /media/NASHDD1//

Please let me know how that goes! :)

Paul on September 10th, 2015 at 7:42am

Following your guide - 'sudo useradd paul –m –G users'
..just displays the 'useradd' help text, and no user is created.
- Raspbian + Ras Pi v2

marosh on September 12th, 2015 at 4:03am

Same problem as Paul :(

Subhajit on September 14th, 2015 at 12:28am

I have followed all the steps, but still the folder not accessible from Windows machine. It prompts for credentials and after giving them, It says, "Windows can't access \\raspberryPi\'Shared Folder Name'.

Andrew on September 17th, 2015 at 11:40am

Have you managed to get Samba 4.3 working; not as an AD controller but just as a file server?

Vijay on September 23rd, 2015 at 2:22am

Hi Gus,
Great NAS tutorial with awesome explanations.
This is my first project with Raspberry pi 2 model B.

I did all the steps as per your tutorial and successfully achieved.
However, on my windows 7 PC I am able to see the folders namely nas and mynamedrive, but i do not have write permissions on both the folders.
I can't create files in that folders, its giving error "you do not have permission for this action".

Please help me to resolve

Gus on September 23rd, 2015 at 2:42am

Hi Vijay,

It sounds like the drive has been mounted with the incorrect permissions or has failed to mount.

If you run the following command it will give you the user and group assigned to the mounted drive.

ls -l /media/mynamedrive

If this displays a user/group that is different to the one you're trying to login as then try running through step 9,10,11 but making sure you assign the correct user. It is also important to note the fstab code in step 11 should all be on one line. If you place this on two lines then the drive will fail to mount and you may get an error like you're describing.

Hope this helps!

Tim on September 24th, 2015 at 11:03pm

Hi Gus,

Problem; 8. Finally you will need to connect the user to samba do this by entering the following: sudo smbpasswd –a pimylifeup

It looks like nothing happens here, i've tried changing "pimylifeup" to my username... but still it appears to do nothing.

I'm able to see the NAS folders in explorer, but can't access them because of username/password issue.

Thanks in advance! really appreciate this tutorial

Kind regards, Tim

Gus on September 24th, 2015 at 11:47pm

Hi Tim,

Can you please try running the following command:

cat /etc/passwd

This should give you a list of users currently created on your Pi.

sudo pdbedit -L -v

If no users appear. Try running this line again but copy it from below.

sudo smbpasswd -a pimylifeup

Hope this helps!

Tim on September 25th, 2015 at 9:33pm

One more question,

Everything works like a charm, i'm able to access everything with every device in my house.

Transfer speed... the top speed i get from my (Laptop) is 2,45MB/s... i'm using WiFi for this, the RPi is wired.

My current OS is Windows 10, i'm currently using two routers, both suffer from the same speed, same thing happens when i use my gf's macbook.

Maybe there's a way to tweak something?

Marko on April 10th, 2016 at 8:48pm

I am having the same problem on windows 10 and macbook

Did you manage to increase transfer speed?

Marko on April 11th, 2016 at 7:51am

I have the same question.
Did you manage to tweak it or increase the speed?

RobV on September 26th, 2015 at 1:08pm

For my first serious pi-roject and after many web-tuts yours finally worked. well sort of. I had to backtrack with rm -rf , rmdir and del user a few times but i got there.

But some puzzles remain.
Accessing it from various PC and Mac's gives me both options of mounting as NASHDD1 and 'public'. After some experimenting it seems an external visitor needs to have a user level identity, which is the reason for ( in my case ) public

However creating a user public ( equiv. to your pimylifeup ) was not really required to the process? could I have just added user pi at Step 8 ( sudo smbpasswd -a pi )? and invite my colleagues in by distributing the pi user.
or is this a security risk in other areas?

I take it the after Step 12 is purely optional

The next step for me is to set up port forwarding on my router, but which is the correct or expected landing point?

Gordon on September 29th, 2015 at 5:44pm

Gus, great tutorial. Thanks. What code do I need to change to add additional hard drives?

Gus on September 29th, 2015 at 6:07pm

Hi Gordon,

The code in step 5 of Raspberry Pi Samba Server section, simply add another block of this into the samba config file (Probably underneath your current one).

Make sure you change the name in the square brackets and the path to the drive.

If you need to mount the drive just back through the steps in the mounting the hard drives section.

Hope this helps!

Luke on October 4th, 2015 at 9:34pm

Great tutorial.

I noticed we didn't use the 'mount' command. Should we have done this at some point? I tried umount /dev/sda1 (because I want to eject the drive) but it says that it wasn't mounted.

Also, when I cat proc/mounts I can't see /dev/sda1

Gus on October 5th, 2015 at 2:48pm

Hi Luke,
We store our mount info in the fstab file so that our mount is restored on reboot. (Essentially the same as using the mount command)

You should target the umount command to the mounted directory as show in the command below:
sudo umount /media/ownclouddrive
That will remove the mount point and you should now be able to safely remove the drive.

If you're not seeing the drive/mount folder in /proc/mounts then it is possible the drive never successfully mounted.

Hope this helps!

Vijay Kumar on October 13th, 2015 at 3:48pm

Hi Gus,
I want to access my NAS drive over the internet. I have forward the port 21 (ftp) in my router. Is this correct port for accessing my NAS drive
Please suggest, how can i access my NAS drive

Jim on October 19th, 2015 at 10:39pm

Hi Thanks for the nice Tutorial, better than the one i read before..

my problem:
the /etc/samba/smb.conf I have looks different, there is no
"security = user " line or documentation for this.
My Authentification paragraph starts like this:

####### Authentication #######
# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller".

Is that a different samba version? mine is 4.1.17-Debian..
Anyway, I can't get it to work.

Gus on October 20th, 2015 at 5:27pm

Thanks Jim, It is possible samba has updated since I did this tutorial. I will need to look into it and work out what's happening!

Clyde on October 21st, 2015 at 2:11pm


just ignore and enter the code as shown in this tutorial..thanks Gus Works like charm!

security = user

comment = NAS Folder
path = /media/NASHDD1
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no

Franklin on November 16th, 2015 at 11:47am

Hi Gus,

Everything worked out fine, but it seems I cannot upload anything to the NAS as I get an error that the file is either to big, or I do not have permission to access some of the items

Hope you can help me out!

Gus on December 7th, 2015 at 8:27pm

Hi Franklin,

If even small files are not transferring it is probably an issue with permissions.

Can you try adding adding writeable = yes underneath [NAS] in step 5 and then restart samba.

ira on November 22nd, 2015 at 11:07am

why is it doing this?

pimylifeup@raspberrypi ~ $ sudo apt-get install samba samba-common-bin
[sudo] password for pimylifeup:
pimylifeup is not in the sudoers file. This incident will be reported.
pimylifeup@raspberrypi ~ $

Gus on December 7th, 2015 at 8:24pm

You have logged in as pimylifeup and it isn't in the list of authorized users to use the command sudo.

You can either add the user into the list of sudoers which I do not recommend or log back in as pi

Ira Robinson on November 24th, 2015 at 10:08am

Hello, I'm trying to make a torrent box.. I'm having trouble with nas part though. I'm not able to make folders in the nas at the end. It says something about permissions.. I'm trying to set it up with a 64g usb and tried using the usb mount guide to start but I'm not sure it's mounting. I've tried setting up the nas using the noob setup then I've tried agen after using Jessie with the usb guide but still get permission problems.

There is no security=user to change in samba?

Kea on December 1st, 2015 at 4:33am

Hi Gus,

I followed your guide and set up the NAS. It is working but one issue when copying a 300mb folder. A message pops up "not enough space in the NAS" when there is plenty of free space. To narrow down the issue, I tried to copy one file 2mb in the folder to NAS, it worked with no issue. So it is only relatively big file/folder has the issue. Please help. Thanks.

Darryl on December 4th, 2015 at 5:15am

I'm trying to setup Samba access to my Pi so I can add/remove files for my website. Since I'm using the Rasp Pi Zero, and inputs are few, and the website itself is tiny, I'm going to host it on the MicroSD directly.

Now the problem:

I can setup the whole thing fine. I can see it from Windows etc. HOWEVER, I have NO write priviledges to the specified folder (in my case "media/website") I can read any folders I create via the command line etc, but I can't do anything from my Windows machine. It just says that I don't have priviledges for this.

Can someone please help??

Gus on December 7th, 2015 at 8:22pm

Hi Darryl,

As the comment below suggests can you try adding writeable = yes underneath [NAS] in step 5 and then restart samba.

If that works then something has changed since I did this tutorial and I will update it accordingly.

James on December 7th, 2015 at 5:43pm

I was unable to write to the NAS folder as others have mentioned, I had to add the following command to the smb.conf file.

writeable = yes
I placed it just about path = /media/NASHDD1

Thanks for this write up!

Gokul on December 13th, 2015 at 12:18am

Need help
raspberry pi(nas folder) is not showing in my network after shutdown and start. Also tried restarting samba manually but it's not working. Don't know what's the problem..

Peter on December 19th, 2015 at 6:19am

i have followed this guide and apparently i dont have all the space. im trying to transfer movie files in to the NAS but it says i dont have space

Amir Segal on December 19th, 2015 at 7:44am

I had the same permission issue many were talking about here, and the solution to my problem was to change the /media/NASHDD1 folder permission with the follwoing:
sudo chown -R MyUser:users NASHDD1
I don’t know if I missed something in he tutorial.

Jon on February 7th, 2016 at 2:31pm

Thanks for the tip. To get mine to function right for the permission, I had to mess with what you wrote until it worked. For anyone else that might be struggling, this is what worked for me:
sudo chown -R pimylifeup /media/NASHDD1

Brian Cok on February 8th, 2016 at 2:00am

Amir, that solved my permissions issue as well. Thanks!