How to Share a Raspberry Pi Folder on a Network

By Renier Delport
Published: 18 May 2016
Filed under:

This is a tutorial on how to share a Raspberry Pi folder on a network to be accessed by other users. Apart from being available to Microsoft Windows operating systems, the shared directory can also be mounted to other Raspberry Pi’s. Last updated: November 24, 2016 at 8:55 am

For this we will be using Samba to create a (non-secure) connection where everyone on the network will have reading and writing privileges to this directory. Non-secure just refers to the fact that, with this tutorial, within your local network you won’t have control of which users can and cannot connect to it.

Requirements

Fully functional Raspberry Pi with Raspbian installed. You will obviously also need the Pi to be connected to a local network. If your Pi is not connected to a screen with a keyboard and mouse, this process can also be done with PuTTY.

How to Share a Raspberry Pi Folder on a Network

First of all, we need to broadcast the share directory onto the network. We will need to install and configure Samba, configure guest privileges and configure the shared folder.

To install Samba run the following terminal command from the root directory of the Pi where the folder you want to share is on:

sudo apt-get install samba samba-common-bin

To configure Samba, we need to edit the /etc/samba/smb.conf file. This file determines what folders are to be shared and who gets access to them. Use

sudo nano /etc/samba/smb.conf

to open the file and in the [global] section, under Authentication, ensure you have the following lines:

[global]
security = user
guest account = nobody
map to guest = bad password

Don’t exit yet.

Linux has a special guest user named ‘nobody’ – which has very little privileges, even less than a regular user.

To be able to share a folder without the user having to supply a password the folder needs to be mapped to the ‘nobody’ user and the password for this user needs to be removed.

To remove the password from the ‘nobody’ user use the following:

smbpasswd -an nobody

To configure your shared folder add the following at the bottom of the file:

[shared-folder]
comment=Shared Folder
browseable=yes
path=/media/share
public=yes
writable=yes
guest ok=yes

Now you can save on exit (Ctrl + X then Y).

At this point I recommend rebooting your Pi sudo reboot

Testing Samba

First of all, see what Samba is doing by using:

service samba status

to test status. If Samba is not running, you can activate it by using:

sudo service samba start

After doing everything as described, Samba should start automatically on after a reboot.

Connecting to the Share

Microsoft Windows

From Windows you can type \\hostname (your own host name) in your browser to access the shared directory. To see the network name of the Pi with the shared directory use hostname in the terminal.

Raspberry Pi

From another Raspberry Pi (or Linux) it’s a bit more complicated. You will need the IP address of the Pi with the shared directory (use hostname -I in the terminal) where you will either see one, or two IPs depending on your setup.

If you have one IP it is probably a dynamically IP obtained during the boot process. This IP might change from time to time! If you have two, one of them is dynamic and one is static. Either way, I recommend using a static IP on the Pi sharing the directory, so if you haven’t done this yet, see Set Up A Static IP Address On The Raspberry Pi or Set Up A Static IP Address On The Raspberry Pi Using Wi-Fi to do so.

When you have the IP address of the Pi with the share directory, we can use the CIFS to mount Samba shares to another Raspberry Pi. The newest Raspbian have it installed, but to make sure run in the terminal:

sudo apt-get install cifs-utils

Now you can use:

sudo mount -t cifs //192.168.1.xx/shared-folder /mnt/share-folder -o password=

Where the 192.168.1.xx is the IP of the sharing Pi, shared-folder is the name configured earlier and /mnt/share-folder is the mounting folder. The password can be anything or nothing.

To unmount the share from user side use umount /mnt/share-folder

Other Useful Samba Commands

Temporarily stop Samba: sudo service samba stop

Even if you stopped Samba as above it will start again on reboot.

Remove Samba from the boot sequence: sudo update-rc.d -f samba remove

This will not stop Samba, but will prevent it from running on reboot. To add Samba back to the boot sequence use:

sudo update-rc.d samba defaults

Please Rate, Share, Comment & Disqus

Was this Post Helpful?

(2 reader(s) found this helpful)
You have not rated this post yet. You can do so clicking on the thumbs up icon.
Loading...

You Might Also Like

Microelectronic components from China
Get Raspberry Pi and other great value for money components from BangGood.com.
22 December 2016

Summary

How to Share a Raspberry Pi Folder on a Network
This is a tutorial on how to share a Raspberry Pi folder on a network to be accessed by other users.
www.behind-the-scenes.co.za

Comment via Facebook

comments so far

Disqus

About the author
Renier is a veterinarian by profession, but apart from his own pets and keeping his animal hospital afloat, he also finds himself busy with creative web design and his websites, motorcycling, photoshopping, micro electronics, non-commercialised music, superhero movies, bad ass seriesses and many other things that is not interesting to most people.
View all posts by Renier Delport