You may often need to copy files such as music, photos or videos between Raspberry Pi and your home PC running Windows operating system. Instead of using USB memory sticks to copy the files across a much easier and safer option is to create a shared folder that can be accessed by both Windows and Raspbian. You can create shared folders in Raspberry Pi and make them available to other devices on Windows network using a software called Samba. Samba is a free software that implements SMB/CIFS protocol to provide shared access to files and printers between Windows, Unix, Linux and OS X systems.
How to install Samba
To install samba on Rasberry Pi simply run the following commands
pi@raspberrypi:~ $ sudo apt update pi@raspberrypi:~ $ sudo apt-get install samba
Configuring Samba
Edit the samba configuration file /etc/samba/smb.conf
pi@raspberrypi:~ $ sudo nano /etc/samba/smb.conf
Change the workgroup name to the name of your workgroup. To find out the workgroup name on Windows 7 PC go to Control Panel → System. On a system running Windows 10 you can find this on Settings → System → About
You can also enable your Raspberry Pi as a WINS server by changing the entry wins support to yes
workgroup = MYWORKGROUP wins support = yes
Replace MYWORKGROUP with the name of your workgroup. Save and exit the file.
Create shared folder
Create the folder that you want to share and setup appropriate permission. In this example we will create a folder and give read, write, execute permissions to owner, group and other users.
pi@raspberrypi:~ $ mkdir /home/pi/shared pi@raspberrypi:~ $ chmod 777 /home/pi/shared
Edit the /etc/samba/smb.conf
file and add the following lines. These lines define the behaviour of the shared folder so you can call them share definition.
[pishare] comment = Pi Shared Folder path = /home/pi/shared browsable = yes guest ok = yes writable = yes
Save and exit the file. You need to restart samba for the changed to take effect.
pi@raspberrypi:~ $ sudo /etc/init.d/samba restart
The following table explains the meaning of each entry in the share definition.
[pishare] | This is the name of the share |
comment = Pi Shared Folder | The text Pi Shared FOlder is the text that is displayed as Comments in shares detail view |
path = /home/pi/shared | Specifies the folder that contains the files to be shared |
browsable = yes | Set this share to be visible when you run the net view command and also when you browse the network shares. |
writable = yes | Allows user to add/modify files and folders in this share. By the default samba shares are readonly |
guest ok = yes | Allows non authenticated users access the share |
Accessing the shares from a Windows machine
- Open File Explorer.
- Click network from the left-hand menu.
- From the list of computers double click RASPBERRYPI (if you haven't change the default hostname)
- You will be see the shared folder pishare. As is it writeable share you can add files to this shared folder from both Windows and Raspberry Pi.