Share Raspberry Pi files and folders with Windows machines

Last 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

Comments

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?

mrdajve | December 20, 2020 10:11 AM |

sudo systemctl restart smbd.service

luk | December 20, 2021 1:01 PM |

same in my case . i have installed required packages, and i can not see samba sercices .

luk | December 20, 2021 12:59 PM |

pi@pi:~$ sudo /etc/init.d/samba restart sudo: /etc/init.d/samba: command not found ehhhh ,

Peter House | January 19, 2021 2:29 PM |

This guide was great for getting started. Thank you. When creating a new file from Windows, the group/user is initialized to nogroup/nobody. Is there a way to control the new group/user? The permissions are set to 744 - can this also be controlled from Windows?

Peter House | January 13, 2021 4:08 PM |

Nice, simple procedure. Mostly worked first time except samba is smbd on my latest RPi OS. Question: Any file I create has the user/group listed as nobody/nogroup. Is there an easy way to fix this? Preferably there is a way to map the incoming permissions to a particular user/group as this would also have the benefit of not requiring a chmod to allow alluser/allgroup on every file.

Tom Howell | January 8, 2021 5:17 AM |

I followed the procedure. Worked fine, I think. My samba seems to be called samba-ad-dc (found looking in /etc/init.d). I commented out the [homes] share. The Pi does not appear in my network on Win 10. Any suggestions?

Tom Welch | January 3, 2021 3:53 PM |

I went through this procedure and I can map a drive from my Windows 10 PC to the "shared" folder. However, when I attempt to copy a file to the shared folder from the Win10 pc I get this message "permission required". I've double checked permissions on the shared folder: drwxrwxrwx 2 pi pi 4096 Jan 3 09:48 shared Any ideas ?

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?

Josiah | June 4, 2020 10:19 PM |

Try `sudo service smbd restart`

mrdajve | December 20, 2020 10:10 AM |

sudo systemctl restart smbd.service

Keith P Neff | September 13, 2020 1:40 PM |

Anybody, is there a solution to the pi not showing in the network on Windows 10?

Gary Volz | September 24, 2018 12:43 AM |

I have setup exactly as per your instructions and tried everything I have been able to find on Internet but can not see the Raspberry Pi on my Windows 10 Network. I also have a Raspberry Pi Nems server on the network but can see that.

Spencer | October 10, 2018 10:13 PM |

I have the same issue. It seems to be common from google searches. Windows 10 does not detect Raspberry Pi samba network drive. The drive is detectable on my non Windows 10 laptop.

Bilbo Baggins | January 12, 2018 11:24 PM |

Windows asking for a password and not allowing access? Make sure the [pishare].. data is placed at the very bottom of the samba config.

binoy | November 20, 2017 5:02 PM |

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

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.

ian | April 24, 2017 7:49 AM |

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

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.

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 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 17, 2017 10:36 PM |

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

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?

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

Thanks Tim, we have updated the article now

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

Patrick | December 22, 2016 8:41 PM |

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

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.