Create a Windows Share on Your Raspberry Pi
If I had to guess at this blog’s readership demographic, I’d imagine that the majority of readers work mainly in the .NET space and within the Microsoft technology ecosystem in general. My background is a bit more eclectic, and, before starting with C# and WPF full time in 2010, I spent a lot of years working with C++ and Java in Linux. As such, working with a Raspberry Pi is sort of like coming home in a way, and I thought I’d offer up some Linux goodness for any of you who are mainly .NET but interested in the Pi.
One thing that you’ve probably noticed is that working with files on the Pi is a bit of a hassle. Perhaps you use FTP and something like Filezilla to send files back and forth, or maybe you’ve gotten comfortable enough with the git command line in Linux to do things that way. But wouldn’t it be handy if you could simply navigate to the Pi’s files the way you would a shared drive in the Windows world? Well, good news — that’s what Samba is for. It allows your Linux machines to “speak Windows” when it comes to file shares.
Here’s how to get it going on your Pi. This assumes that you’ve setup SSH already.
- SSH into your Raspberry Pi and type “sudo apt-get install samba” which will install samba.
- Type “y” and hit enter when the “are you sure” prompt comes up telling you how much disk space this will take.
- Next do a “sudo apt-get install samba-common-bin” to install a series of utilities and add-ons to the basic Samba offering that are going to make working with it way easier as you use it.
- Now, type “sudo nano /etc/samba/smb.conf” to edit, with elevated permissions, the newly installed samba configuration file.
- If you go navigate to your pi’s IP address (start, run, “\\piip”), you’ll see that it comes up but contains no folders. That’s because samba is running but you haven’t yet configured a share.
- Navigate to the line in the samba configuration file with the heading “[homes]” (line 244 at the time of this writing), and then find the setting underneath that says “browseable = no”. This configuration says that the home directories on the pi are not accessible. Change it to yes, save the config file, and observe that refreshing your file explorer window now shows a folder: “homes.” Cool! But don’t click on it because that won’t work yet.
- Now, go back and change that setting back under homes because we’re going to set up a share a different way for the Pi. I just wanted to show you how this worked. Instead of tweaking one that they provide by default, we’re going to create our own.
- Add the following to your smb.conf file, somewhere near the [homes] share.
- Here’s what this sets up. The name of the share is going to be “pi” and we’re specifying that it can be read, written, browsed. We’re also saying that guest is okay (anyone on the network can access it) and that anyone on the network can create files and directories. Just so you know, this is an extremely permissive share that would probably give your IT/security guy a coronary.
- Now, go refresh your explorer window on your Windows machine, and viola!
- If some of the changes you make to samba don’t seem to go through, you can always do “sudo service samba restart” to stop and restart samba to make sure your configuration changes take effect. That shouldn’t have been strictly necessary for this tutorial, but it’s handy to know and always a good first troubleshooting step if changes don’t seem to go through.
And that’s it. You can now edit files on your Pi to your heart’s content from within Windows as well as drag-and-drop files to/from your Pi, just as you would with any Windows network share. Happy Pi-ing!By the way, if you liked this post and you're new here, check out this page as a good place to start for more content that you might enjoy.
Hi – I’m getting “you need permission to perform this action” error from windows when I try to copy to a Pi folder. Navigation & read works – just no “write”. Any ideas?
It might be a question of the Pi’s Linux directory permissions. If you go on the Pi to the directory in question and then do “chmod 777” you can see if you’re able to write. If so, it was a Linux permissions issue.
Thanks – sorted.
sudo chmod -R 777 /home/pi/
Glad if it helped. Not bad for a blind shot at the problem 😀
Heh. And I’ve spent the past couple hours trying to figure out this same issue myself. A couple tutorials, and nothing was working. This comment, and Boom! Fixed. Thanks!
Happy to hear it! I’ve been in your position so, so many times that I know what a relief that is (though sometimes also infuriating)
tks for this tutorial..
strange enough i’ve got under win7 a popup windows asking for user and password..weird ?
I think that’s normal the first time you access it. If you type in the login credentials for the pi (i.e. pi/raspberry), it should probably cache them in the Windows credential manager and you won’t have to do it again.
ah ok tks erik i’ll do it then….for the story, i used this way to retrieve files from the pi :http://schoolpiclub.wordpress.com/2014/04/08/transferring-files-from-raspberry-pi-to-a-computer-using-filezilla/ ..
Hey Erik, thanks for the tutorial. I’m 95% there, but getting hung up at the last step- hope you can help. Installed samba, edited samba.conf to share a directory off my home. On win8.1 box, open \rpi-ip, I see my share listed along with a printer I previously shared. When I double-click to open the shared folder, I’m asked for credentials. I’ve tried all kinds of permutations of username/password/domain name, nothing is working (keep getting bounced back to “supply credentials” dialog, sometimes immediately sometimes long delay). Tried various “sudo chmod -R 0777 homepisharename” incantations, as well as various “domainuser ”… Read more »
Never mind- got it! My smb.conf was all messed up- I stuck my share configuration right in the middle of the [home] config slot. Then a few remaining issues with permissions on the linux side (added create mask = 0777 and directory mask = 0777 to smb.conf, and also “chmod 0777 sharedir” on the shared directory).
Thanks again for the tute.
No worries, and glad you got it sorted. I was sort of off the grid for the holiday weekend, but it’s also been a while since I played with this, so I’m not sure exactly how much help I would have been 🙂