This article carries on from Automatically mount multiple drives, so if you already have a folder to share (such as the home directory) carry on reading, otherwise it is recommended to go back and set up a drive to be shared.
What we plan to achieve
Having a Raspberry Pi on a network is great when browsing the internet or updating software, but sometimes the need to copy files and folders would be handy, now Windows offers Folder sharing making this very easy amongst themselves, but for those new to the Linux world this can be too daunting. For years the Linux world has always had SAMBA to help remove the barriers between Linux and Windows, but setting it up quickly and easily is a bit hit and miss.
So this guide will help set up the home directory on the Pi – Great if the Raspberry Pi is acting as a timelapse or a web server – Or a removeable USB hard drive to store pictures or media and then map a drive on Windows to access them as if it is another drive on the computer. This mapping can be performed to many Windows computers allowing sharing as easy as drag and dropping! Great for kids homework too.
Installing the needed software
First of all, is to install the SAMBA server on the Raspberry Pi, so type via SSH or LXTerminal (internet connection required);
sudo apt-get update sudo apt-get install samba samba-common-bin -y
First thing we will do is add the default user (pi) to the SAMBA server and create a password. This is the login that will be used to access the files over the network, so make sure it is something you will remember, or share to other network users if needed;
sudo smbpasswd -a pi
Configuring configuration config files
The configuration file lives in the folder /etc/samba/. So first we will navigate here, rename the original configuration and create ourselves a new one;
cd /etc/samba sudo mv smb.conf smb.old sudo nano smb.conf
Now paste the following block in. The following configuration has the server setup titled [global] and then 2 mappings for different folders called [Pictures] and [Home].
[global] workgroup = WORKGROUP server string = %h server (Samba) wins support = yes dns proxy = no log file = /var/log/samba/log.%m max log size = 1000 syslog = 0 panic action = /usr/share/samba/panic-action %d server role = standalone server obey pam restrictions = yes unix password sync = yes passwd program = /usr/bin/passwd %u passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully$ pam password change = yes map to guest = bad user usershare allow guests = yes [Pictures] comment=Media Drive path=/media/pictures browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no valid users=pi [Home] comment=Media Drive path=/home/pi browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no valid users=pi
The settings for global will be enough to get the server live on the network, whereas the [Pictures] is requesting to access the folder /media/pictures that was created in the previous guide. The second, named [Home] will be serving the /home/pi folder, making it very easy to transfer files between the Raspberry Pi and a Windows computer.
If you don’t intend to use the Pictures section, just remove the entire section, or if the files are located elsewhere, just amend the path to point to the new location.
Last thing to remember is the name of the sections (Pictures and Home) will relate to the name of the share folder.
So finally save the configuration file with CTRL + X, Y, and Enter. And restart the SAMBA daemon to reload the changes;
sudo service smbd restart
Mapping a drive in Windows
First thing that we’d need is the IP address of the Raspberry Pi, so whilst still in LXTerminal/SSH, type;
As you can see in my example, the Pi is connected via ethernet cable and reports an IP address of 192.168.0.16. Yours may be different so take time to check the output for the inet addr, make a note of the IP address.
Lets see if Windows can see the Raspberry Pi. On the Windows computer, open Computer (formally My Computer). In the address bar at the top, type in;
Obviously replacing it with the IP address of the Raspberry Pi.
Followed by enter;
If everything is successful, you should see the folders created within the configuration file above, and upon double clicking will present a login box. Using pi for the User Name and the password created with smbpasswd. You will then see the list of files.
Mapping the drive
Go back a folder to the list of shares;
Right click the folder (only one can be mapped at a time), and click Map network drive…, choose the drive letter or leave as Z: (or next one available if it is in use) and follow by clicking Finish. The mapped folder will then open showing the folder contents.
If you wish to map multiple drives, just repeat the steps above.
The mapped drives will appear in Computer making them easy to access, and can be used from most Windows applications as a place to open or save files.
Now we have a fully usable network drive, capable of sharing files between many people – Although bear in mind only 1 person can edit a file at a time to stop file corruption. File permissions may in some set-ups play a role during use, but as there are many different types of file and network permission it’ll be too much to list, but on request I may create a guide to cover the most commonly seen – just email me any problems to create for.