Share Raspberry Pi files and folders with Windows machines

Updated on 11th February 2016

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 FolderThe text Pi Shared FOlder is the text that is displayed as Comments in shares detail view
path = /home/pi/sharedSpecifies the folder that contains the files to be shared
browsable = yesSet this share to be visible when you run the net view command and also when you browse the network shares.
writable = yesAllows user to add/modify files and folders in this share. By the default samba shares are readonly
guest ok = yesAllows 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.

Post a comment

Got a question about this article? Ask our forum

Name

Your Comment

Email (We dont publish it)

Comments

Rickey | December 22, 2016 8:33 PM |

In the example for the samba conf file, you misspelled browseable, so if this is typed verbatim it will not work. The 'e' is missing.

Patrick | December 22, 2016 8:41 PM |

browsable is synonym for browseable according to samba docs here so both should actually work

Tim | January 2, 2017 1:31 PM |

The article should mention that it is necessary to restart samba before any changes to /etc/samba/smb.conf will take effect: sudo /etc/init.d/samba restart

OTG Team | January 2, 2017 1:41 PM |

Thanks Tim, we have updated the article now

TSS | January 17, 2017 10:19 PM |

Thanks this is exactly what I wanted. But I find that I can actually see alll teh file under /home/pi and not just the shared directory. I added as follows. [PiShare] comment=Raspberry Pi Share path=/home/pi/shared browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no How do I restict it to just the shared directory?

Patrick | January 17, 2017 10:36 PM |

@TSS: Disable the share named [homes] in smb.conf file

TSS | January 19, 2017 7:43 PM |

Many Thanks that resolved that issue. I am running Windows 10. I cannot see my Pi in my browser window? Also when I mannually try and map a network drive using \\x.x.x.x\shared I get the prompt to logon but the password does not work.

Patrick | January 19, 2017 7:46 PM |

Have you tried prefixing user name with your pi hostname\ipaddress..like xxx.xxx.xxx.xxx\username

TSS | January 20, 2017 10:24 PM |

Many thanks. Tried that and it still does not accept the password. It shows the correct logon at the top but the password does not work.

ian | April 24, 2017 7:49 AM |

i don't see it when i go to network in file explorer.

Paul B | May 6, 2017 11:45 AM |

Worked great as soon as I figured out pc and pi were names were simular. Can be confusing but I figured it out. Works fine lasts a long time.

andrew | November 20, 2017 4:59 PM |

When I try to restart samba, I always get the message "command not found". What could be the problem?

andrew | November 20, 2017 4:59 PM |

When I try to restart samba I get the message "command not found". What could be the reason for this?

binoy | November 20, 2017 5:02 PM |

Seems samba is not installed . Did you run sudo apt-get install samba