This post will demonstrate how you can share files from your RPi, to all your Windows machines that are within your LAN.
- Start off by updating your repositories and currently installed packages:
sudo apt-get update && sudo apt-get upgrade
- 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
- You will also need ntfs-3g if your external hard-drive is of NTFS format.
sudo apt-get install ntfs-3g
- Create the directory of where you want to mount your external hard-drive.
sudo mkdir [-m 1777] /media/exthdd1
- 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
- Ctrl + X, type y, and press enter to save. Your external drive will now automatically mount upon boot.
- 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
- Press CTRL + W, type for “security =” and press enter. Uncomment the configuration line, not the description line.
- 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.
- 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.
- 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
- Ctrl + X, type y, and press enter to save.
- 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.
- 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
- Restart the samba service in order for all changes to take effect.
sudo /etc/init.d/samba restart
- 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
If you’ve followed everything step-by-step in this post, and you’ve got all the way up to typing \\192.168.0.5\exthdd1 into your Windows Explorer bar and it just won’t load… Then try disabling the VirtualBox Host-Only Ethernet Adapter in Device Manager. Your samba share is attempting to connect to 192.168.0.5 using VirtualBox’s NIC. Silly VirtualBox.
During my journey in setting this up, I (and many others by the looks of Google) encountered issues where I couldn’t write to my external hard-drive from Windows. It was a permissions error. I narrowed it down to what was configured in /etc/fstab. Originally, I had uid=1000 and gid=1000 set, as opposed to uid=pi and gid=pi. Since I suggested you to use uid=pi and gid=pi, then I doubt you’ll experience issues, but just in case you do… Give this a go:
- Open Microsoft Management Console by clicking the Start button Picture of the Start button, typing mmc into the search box, and then pressing Enter. Administrator permission required If you’re prompted for an administrator password or confirmation, type the password or provide confirmation.
- In the left pane, click Local Users and Groups.
- If you don’t see Local Users and Groups
- If you don’t see Local Users and Groups, it’s probably because that snap-in has not been added to Microsoft Management Console. Follow these steps to install it:
- In Microsoft Management Console, click the File menu, and then click Add/Remove Snap-in.
- Click Local Users and Groups, and then click Add.
- Click Local computer, and then click Finish.
- Click OK.
- Double-click the Users folder.
- Double-click on your username.
- Navigate to the “Member Of” tab.
- Click Add, and then type “Users”
- Click Check Names, and then click OK.
- Click OK again.
- Close, and when prompted, you do not want to save settings to Console1 file
That should do the trick. Comment below if it doesn’t and I will try my best to help you.
This post is part of the Public Accessible Raspberry Pi File Server tutorial post.