Raspberry Pi: network file sharing with samba

This post will demonstrate how you can share files from your RPi, to all your Windows machines that are within your LAN.

  1. Start off by updating your repositories and currently installed packages:

sudo apt-get update && sudo apt-get upgrade

  1. Then progress to install samba, along with samba-common-bin. samba-common-bin will provide you with the testparm utility, that checks your smb.conf file for errors in used syntaxes. This may take a while…

sudo apt-get install samba samba-common-bin

  1. You will also need ntfs-3g if your external hard-drive is of NTFS format.

sudo apt-get install ntfs-3g

  1. Create the directory of where you want to mount your external hard-drive.

sudo mkdir [-m 1777] /media/exthdd1

  1. Just before we alter the samba configuration, open /etc/fstab in nano and add the below line of text.

sudo nano /etc/fstab

/dev/sda1	/exthdd1	ntfs-3g	uid=1000,gid=1000,rw,user,exec,umask=0022	0	0

etcfstab

  1. Ctrl + X, type y, and press enter to save. Your external drive will now automatically mount upon boot.
  2. Open up your smb.conf file in /etc/samba/ you will see it is jam packed with comments (comments start with a semi-colon or a hash). Here you will make use of the “Where Is” utility within nano.

sudo nano /etc/samba/smb.conf

  1. Press CTRL + W, type for “security =” and press enter. Uncomment the configuration line, not the description line.
  2. Press CTRL + W, type for “encrypted passwords =” and press enter. Change the value to “yes“. This is a requirement for all Windows machines, for passwords to be interpreted at either end as encrypted – according to smb.conf manual page anyway.
  3. Scroll all the way to the bottom (tip in nano, press CTRL + V to scroll through pages). Once there, this is where you specify the directory you want to share, what you want to call it and any extra configurations you want to use. See the smb.conf manual for a detailed list of all configurations you can make, though here I will give you the essentials.
  4. At the bottom of the smb.conf file, enter the below:
[share]
path = /exthdd1
browseable = yes
read only = no
writeable = yes
directory mask = 0777
create mask = 0777
  1. Ctrl + X, type y, and press enter to save.
  2. This is your chance to use testparm in order to check there has been no syntax error mistakes in the samba configuration file – you will be be notified if there are any errors.

testparm

  1. Establish a new user and password to grant access to your Samba share – the username given must also be a system user. Thank you Detlef.

sudo smbpasswd -a pi

  1. Restart the samba service in order for all changes to take effect.

sudo /etc/init.d/samba restart

  1. You should now be able to access your shared samba directory from other devices within your LAN. Give it a go by typing the below into your Windows Explorer bar. You will be prompted for credentials – sign in with your password for the “pi” username and you’re good to go.
\\**YOUR IP ADDRESS**\fileshare

Windows Explorer

Having problems?

 

This post is part of the Public Accessible Raspberry Pi File Server tutorial post.

4 Comments:

  1. Hi, maybe I missed it, but can’t find where the samba-pw is established with
    “sudo smbpasswd -a pi”
    Once I did this, it all worked fine.

  2. I took your advice for having “permission denied” when trying to write to the mounted device and it didn’t work……

    • Hi Nick,

      Sorry for late reply. Can you please share with me your /etc/fstab file please – send comment back with your email and I’ll be sure to get in contact.

Leave a Reply

Your email address will not be published. Required fields are marked *