If you work with the RaspberryPi you will sooner or later encounter the problem of how to transfer files to the RasPi or copy them from the RasPi.
There are different ways to do that. An easy way is the transfer via FTP or SFTP.
When communicating with your RasPi over the Internet, one of them is certainly your first choice. However, if you work in the home network, it is much more comfortable to exchange the files directly via Windows Explorer.
To make this possible you have to set up a share on the RasPi, which you can then integrate under Windows as a network drive.
How to do that and what you should pay attention to in the following article.
Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section.
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂
- 1 Safety instructions
- 2 Affiliate links / advertising links
- 3 Requirements
- 4 Log in via SSH on the RaspberryPi
- 5 Update package management
- 6 Install the required programs or packages
- 7 Create the folder to be shared
- 8 Customize the Samba configuration file
- 9 Set up a user account
- 10 Set up network drive under Windows
- 11 Have fun with the project
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Before you start with this article, you should have prepared the RaspberryPi so far that it can be reached via the network and controlled by SSH.
The following three articles describe what to do to prepare the RaspberryPi:
RaspberryPi – Setting up for Nerdiys!
RaspberryPi – The First Configuration!
RaspberryPi – Control the RaspberryPi via SSH
Basics of navigation in Windows Explorer
In the following list you will find all the parts you need to implement this article.
Log in via SSH on the RaspberryPi
To get started, you first need to log in to RasPi with SSH on Putty. How to do it is described in the article
Update package management
The package management in Linux is a "central point" over which various software packages can be installed. For this to work reliably, the lists and sources of package management should be updated before installing any new packages.
sudo apt-get update && sudo apt-get upgrade
Install the required programs or packages
To be able to share a folder, you need of course a corresponding program called Linux package. The required package is called “Samba”. You can install this “samba” with the following command:
sudo apt-get install samba
You confirm these demands with a “j”(or “y”) and enter. The installation will then continue.
In order for you to be able to share access to a folder, you must first create a corresponding folder in your home directory.
This is done with the following command:
In the screenshot you can see the home directory before and after the folder “share folder” was created.
In the view of the home directory after creating the folder, the (red underlined) “Release Folder” will be available.
Customize the Samba configuration file
Now we have to tell “Samba” where the folder to be shared is and under what conditions we would like to release it. This can all be set in the Samba configuration file. This is called smb.conf. To edit them you need to execute the following command:
sudo nano /etc/samba/smb.conf
[PiFreigabe] comment=Raspi Sharepath=/home/pi/FreigabeOrdner browseable=Yes writeable=Yes only guest=No create mask=0740 directory mask=0750 public=no
It is easiest if you mark the text, copy it and then paste it in the text file with a right-click in the relevant place.
If you have chosen a different folder name or location for your shared folder, you will need to change the corresponding part under “path”.
These configuration settings will allow you to have read and write permissions in the folder, to be able to browse it, and to allow only users who have previously logged in with username and password to access it.
In order to save the changes you have to press CTRL + X on the keyboard and confirm the request if you want to save before closing with a “j” (or “y”=yes) and ENTER.
This saved your recent changes to the configuration file.
Samba is automatically restarted and the new configuration is taken over.
Set up a user account
Since you have configured the sharing by the information in the configuration file so that only users with username and password can access them, we now have to create a username with a suitable password.
This user name is the same as the currently used Linux user. The password may be different from this.
For example, to create the user “pi” you need to execute the following command:
sudo smbpasswd -a pi
Set up network drive under Windows
With the configuration under Linux you are now finished.
Now you have to configure the shared folder in Windows as a network drive. You can then finally access the shared folder as if it were a local drive (that is, connected directly to your computer).
To configure this network drive, open the “Computer”. So the window in which you also plugged USB sticks, CD/DVD drives and hard drives are displayed.
But you also have to tell Windows that it should use the user account that was created on the RaspberryPi.
Attention now it gets a bit complicated:
This is done by setting the user name, separate from a backslash (ie, the slash on the sharp s key on a germany keyboard-layout), to the user’s domain. The domain of the user in this case is your RasPi.
Long story short:
So you do not just type in “pi” but
In my example, this would then be
The password is entered as normal in the password line.
Then you click on “OK”.
The window then closes and a new window opens shortly thereafter.
This folder now shows you the contents of the shared folder on the RasPi. All files that you now copied into this drive are copied directly to the RasPi.
You now know how to share a folder on the RasPi and connect it as a network drive on a Windows system.
Have fun with the project
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂