HowTo: RaspberryPi – Share folders with SMB and integrate them as a network drive under Windows

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 several ways to do this. A simple way is the transfer via FTP or SFTP.

If you communicate with your RasPi over the Internet, one of the two is certainly the first choice. But if you work in your home network it is much more comfortable to exchange files directly via Windows Explorer.

To make this possible you have to set up a share on the RasPi, which you can then mount as a network drive under Windows.

How to do that and what you have to pay attention to I have described in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you start with this article you should have prepared the RaspberryPi so that it is accessible via the network and controllable via SSH.

The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
Basics of navigating in Windows Explorer

Required tool:
-no-

Required material:

In the following list you will find all the parts you need to implement this article.


Log in to the RaspberryPi via SSH

To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.

After entering your username and password you can enter the first commands.

Update package management

The package management in Linux is a "central place" through which various software packages can be installed. In order for this to work reliably, the lists and sources of the package management should be updated before each installation of new packages.

To start the update of the package management you have to enter the following command.
sudo apt-get update && sudo apt-get upgrade
Depending on how long ago your last update of the package management was, this process can now take a while. The lists that refer to the individual package sources are updated first.
After that, the packages themselves are updated. Since additional memory is occupied, you will be asked again for your consent. You have to confirm this with a "J" and "Enter".
Once the update is complete, you will see a small summary of the duration and scope of the update.

Install the required programs or packages

So that you can share a folder you need of course a corresponding program which is also called package under Linux. The required package is called "Samba". You can install this "Samba" with the following command:

sudo apt-get install samba
During the installation of the updates and the following packages you may be asked if you agree that the modules to be installed take up additional memory.

Confirm these questions with a "j" and Enter. The installation will then continue.


Create the folder to share

In order to share access to a folder, you must first create a folder in your home directory.

This can be done with the following command:

mkdir ~/SharedFolder
This creates a folder in your home directory called “ShareFolder”. The “~/” in front of the folder name indicates that this folder should be created in your home directory.

In the screenshot you can see the home directory before and after the folder "ShareFolder" was created.
In the view of the home directory after creating the folder, the (red underlined) "ShareFolder" is then present.


Customize the Samba configuration file

Now we have to tell "Samba" where the folder to share is located and under what conditions we would like to share it. This can all be set in the Samba configuration file. This is called smb.conf. To edit it you have to execute the following command:

sudo nano /etc/samba/smb.conf

After you have opened the configuration file you maneuver the cursor with the arrow keys to the end of the file (i.e. all the way down). There you insert the following configuration text:

[Pi release] comment=Raspi Sharepath=/home/pi/release folder browseable=Yes writeable=Yes only guest=No create mask=0740 directory mask=0750 public=no

The easiest way to do this is to select the text, copy it, and then right-click to paste it into the appropriate location in the text file.

If you have chosen a different folder name or location for your shared folder you have to change the corresponding part under "path".

These configuration settings ensure that you have read and write permissions in the folder, that you can browse it and that only users who have previously logged in with a user name and password can access it.

To save the changes you have made, press CTRL+X on the keyboard and confirm the question whether you want to save before closing with a "y" (=yes) and ENTER.

This saved the changes you just made to the configuration file.

Samba will be restarted automatically and the new configuration will be applied.


Set up a user account

Since you have configured the share by specifying it in the configuration file so that only users with a username and password can access it, we now also need to create a username with a matching password.

This user name is the same as the Linux user currently in use. However, the password may be different from this one.

For example, to create the user "pi" you need to run the following command:

sudo smbpasswd -a pi
After entering the password, you will be prompted to enter the same password twice. The double entry is intended to prevent you from mistyping the single entry and thus saving an incorrect password that you do not know.

Set up network drive under Windows

Now you are done with the configuration under Linux.

Now you have to configure the shared folder in Windows as a network drive. You will then be able to access the shared folder as if it were a local drive (i.e. directly connected to your computer).

To configure this network drive, open the "Computer". This is the window in which inserted USB sticks, CD/DVD drives and hard disks are also displayed.

In order to see the menu entry with which you can connect a network drive, you must first show the menu bar (if it is not already shown.) To do this, click on the small arrow (circled in red).
Now click on "Connect network runner" in the upper bar.
...and then click on "Browse" in the window that opens. There you should see all computers that are available in your network.
The RaspberryPi used in this example is called "MAGICMIRROR". You have defined the name of your RasPi yourself and it should be found here now. To set up the network drive you have to click on the name of your RasPi.
A window will open in which you should enter the user name and password that authorizes you to access this computer. You have created or set this user/password combination before.

But you also have to tell Windows to use the user account that was created on the RaspberryPi.

Attention, this is going to get complicated for a moment:
You do this by prepending the user's domain to the user name, separated by a backslash (i.e. the slash on the sharp s key). The domain of the user in this case is your RasPi.

Long story short:
So you enter not only "pi" but also

"nameEuresRasPisprovidedUserName"

one.
In my example this would then be

"magicmirrorpi"

are.

In the password line, the password is entered normally.
After that click on "OK".

...and you will find yourself in this window. Now select your shared folder, check "Reconnect on login" and click on "Ok" and "Finish".

The window will close and a new window will open shortly afterwards.

This is the network drive that is now connected.

This folder shows you now directly the content of the shared folder on the RasPi. All files that you copy to this drive will be copied directly to the RasPi.


So now you know how to share a folder on the RasPi and mount it as a network drive on a Windows system.

Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS 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 think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

3 comments

  1. Hi everyone,

    I had put the question in the wrong post yesterday, sorry for that.

    My problem is that, although I can integrate the external HDD (3.5” with its own power supply) into OMV and can also provide shares under Windows, no files or folders are displayed on the network drive. Message: “Folder is empty”.

    Another external SSD (Nvme with adapter) shows up and I can access all files.

    Actually, it can only be the HDD or the file format, or am I wrong here? The file format of the 3.5″ is NTFS, that of the small BTRFS.

    What is striking, under Storage - Shared Folders the usual path is displayed under Device for the Nvme:
    /dev/sda, with the large partition name “Movies” .

    The absolute path, however, is displayed correctly. Does anyone have a tip for me what the problem could be. The tutorial is great and I followed it the same way, but without success.

    Oh yes, Windows does not require a username and password when creating the network drive.

    Thank you already.

    greeting

    Markus

    1. Hi Markus,
      so ad hoc I have no direct idea. It should actually also work with NTFS.
      Can you copy the output of the “df -h” command here for me when the 3.5″ hard drive is connected.
      This should list all attached drives including their mountpoints 🙂 .
      Best regards
      Fabian

  2. Hey. Great instructions, thank you.

    Unfortunately it says that my hard drive is write protected, even though I have assigned all rights.

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.