Raspberry Pi samba share in 5 minutes

Use the 35$ Raspberry Pi and create a Network share with Public and Personal share settings in about 5 minutes. The shared folders can be accessed over the network by machines running Windows, Mac, Linux or Android.

Overview :
  • Create a folder that you want to share.
  • Download Samba.
  • Edit the  Samba configuration and create the share.
Time and Difficulty :
  • Time : 5  mins  once you have the Pi running on Raspbian.
  • Newbie Difficulty level : Easy ; Will need to use terminal and type in commands.
Creating the Raspberry Pi samba share in 5 minutes :

In this tutorial, We create two shares on USB Hard drive at the /mnt/hdd location. Click here to read about automounting a USB Hard Drive to your Raspberry Pi.

Make sure the Raspberry Pi is upto date by entering :

sudo apt-get update
sudo apt-get upgrade

Navigate to the location on your Pi where you want the share to be created and Create a directory Share by running :

sudo mkdir -m 777 /mnt/hdd/pishare  (in this case, a folder called pishare has been created inside /mnt/hdd with RW permissions)

sudo mkdir -m 777 /mnt/hdd/publicshare  (in this case, a folder called publicshare has been created inside /mnt/hdd with RW permissions)

sudo apt-get install samba samba-common-bin (Install Samba framework )

sudo cp /etc/samba/smb.conf /etc/samba/smbconf.backup  ( Make a back up of the current smb.conf file into a new file called smbconf.backup )

sudo nano /etc/samba/smb.conf  ( Use Nano the word editor to edit the file smb.conf)

Inside nano, navigate to the section [global], under workgroup = WORKGROUP, add the following line

netbios name = HOBBIT ( This sets HOBBIT as the name of the Raspberry Pi when viewed in a Windows network )

Next, Navigate down to under Share definitions and  comment out the existing share definitions by adding a # before each line.

Under Share definitions, to create a Share for user Pi, Enter the following :

[PiShare]
path = /mnt/hdd/pishare
comment = Pi's Share Folder
valid users = pi
read only = No
create mask = 0777
directory mask = 0777

To create a Public Share, Enter the following :

[PublicShare]
path = /mnt/hdd/publicshare
comment = Public Share Folder
guest ok = yes
read only = No
create mask = 0777
directory mask = 0777

Press Ctrl+X to exit and Y to save. Your Share definitions should look something like this.

smb.conf with shares defined
smb.conf with shares defined

To restart Samba with the new configuration file, Enter :

sudo service smbd restart

sudo service nmbd restart

Since Samba has it’s own Password config, Run :

sudo smbpasswd -a pi ( To give user pi a new password for Samba to use while logging in from a network machine )

Your Raspberry Pi is now a Network File Server called HOBBIT with two shares ; One Private and One Public.

From your Windows Machine, Enter \\HOBBIT.  You should see the Newly created Shares.

In Explorer,Enter \\HOBBIT to see the Pi on the network
In Explorer,Enter \\HOBBIT to see the Pi on the network

For the private share, use the login HOBBIT\pi  

Use HOBBIT\pi as the log in and enter your password.
Use HOBBIT\pi as the log in and enter your password.

For Public Share, no authentication will be required.

 

 

12 thoughts on “Raspberry Pi samba share in 5 minutes”

  1. getting this when i do sudo service samba restart.

    Failed to restart samba.service: Unit samba.service is masked.

    i added # to every line after Share definitions.. should i have done this

  2. Im getting the 2 following errors:
    1. on sudo service samba restart: Failed to restart samba.service: Unit samba.service is masked.

    2. on sudo service smdb restart: Failed to restart smdb.service: Unit smdb.service failed to load: No such file or directory.

    I previously ran sudo apt-get install samba followed by an update and an upgrade as well as edited the smb.conf file.

    Please help

  3. Same problem here… I reinstalled samba at least 5 times on fresh RP, tried all the proposed solutions above, but failures are constant… Configuration: Raspbian latest version, RP3 model B. Did somebody have been successful in fixing the problem?

  4. Thanks for the note! I finally discovered the source of the problem: it might be a bad idea to copy/paste a file from Windows to the RP! Manually typing the file content seems to fix the problem. Samba now works perfectly. Thanks again!

    1. Yes, copy and paste from a ‘formatted text’ source in windows sometimes leads to additional characters being inserted while pasting. One good work around is to first paste into notepad where the format of the text is stripped away. Then , copy from notepad and paste into the puttty terminal.

Leave a Reply