Setting up file sharing/NAS using Samba on Raspberry Pi

n this tutorial, we shall find step by step guide on setting up a “file sharing”/ “file server”/ NAS using samba.

For file sharing, we shall to CIFS/SMB also known as windows file sharing protocol implementation on Raspberry Pi.
We are assuming you already have an external storage connected and mounted in your Raspberry Pi box. We are using Raspbian for this implementation. If not use this blog article for a step by step guide on Mounting USB Storage/external disk (FAT file system) on Raspberry Pi for Local or Network storage

Install samba

Login to your Raspberry Pi console
If you haven’t done so, run the following to make your distribution up to date
Update and upgrade
sudo apt-get update
sudo apt-get upgrade -y
Install Samba
sudo apt-get install samba
sudo apt-get install samba-common-bin
We shall use the folder “/nas” in raspberry Pi we created from the earlier tutorial. We shall share “/nas” using SMB protocol. To do this, we shall need a samba account in our raspberry Pi. We shall use the user account “pi” in this case. you may use any other existing user of your choice. Enter the following command and type in a password to set the samba password for “ip” user :
sudo smbpasswd -a pi
once executed you shall be prompted as following:
New SMB password:
Retype new SMB password:
Added user pi
note down this new password, you shall be asked for it later on. Note: this password will not affect your login to Raspberry Pi over ssh.
Before we edit the samba configuration we shall create a backup file to recover from any unwanted changes
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orig
 Edit the /etc/samba/smb.conf file using nano by executing the following command
sudo nano /etc/samba/smb.conf
add the following section in to the smb.conf file
comment = Media share
path = /nas
force user = “root”
read only = no
guest ok = yes
public = yes
sudo /etc/init.d/samba restart

Client access to samba share

Check if samba service is enabled on startup, so that the service starts on reboot (usually it is)

sudo service --status-all | grep  samba

This may take a few seconds, you shall expect an output such as

sudo service --status-all
sudo service –status-all

The “[ + ]” indicates the service is active on startup

In case, the service name is followed by a “[ – ]” run the following commands to enable samba services on startup

sudo update-rc.d smbd defaults

This will enable samba on startup, which is set to by default.

Reboot and check client access

sudo reboot

Client access to NAS

provided the raspberry pi is on the same network run the following in the “search program and files box” from your windows command prompt
or with ip address
search program and files box
When prompted for password, Enter user name “pi” and password you noted down earlier in this section then prompted for.
On mac 
If you are a Linux user, this command should mount the NAS drive for you:
Enter user name “pi” and password you noted down earlier in this section then prompted for.
sudo mkdir /pishare
sudo smbmount -o username=pi,password=raspberry //ip.address.of.raspberry.pi/USB /pishare
Install ES explorer on from google play store on your mobile
from the appliction go to options -> network -> search
you shall find the nas server and access files from it. for detailed how to follow this link
Enter username “pi” and password you noted down earlier in this section then prompted for.
1. Update and upgrade the system
2. Install samba
3. Set samba password for the user “pi”
4. Edit /etc/samba/smb.conf to add a public share for the local network
5. Restart samba
6. Make sure samba service starts on reboot
7. Check clinet access on windows/mac/android etc.

2 thoughts on “Setting up file sharing/NAS using Samba on Raspberry Pi

  1. Perhaps I’ve done this wrong. the share shows up in windows network explorer. however, when I try to access it, I do not get the usual windows pop up asking for my user name and password. instead I get an error from windows saying my user name is not found. Since windows has no idea of the use name and password I set up, I can only assume it is trying to log into my samba share using my windows username/password. that isnt going to work. so how do I make windows ask for my samba share user name and password? im using raspbian jessie on a raspberry pi3.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s