Raspberry Pi: Sharing Network Folders with Windows Computers

Regardless of the purpose for which a Raspberry Pi is primarily used, a shared directory is a basic function in any home network, and a continuously operating Pi is excellently suited to handle this task on the side. This short guide is suitable for creating a shared directory using Samba on the network, which can be accessed as a NAS (network attached storage) by both Windows and Linux devices alike.

Requirements

  • Raspberry Pi
  • SD card or MicroSD card (depending on model)
  • A home network, typically via a router
  • Raspbian operating system (installing the operating system on the memory card was already described in detail at the beginning of this guide)
  • One or more devices with which we can access the network

Installation

In the following, it is assumed that Raspbian is installed, the Pi is accessible on the network, and we are connected to it via SSH, thus having access to the console. The first steps, from installing Raspbian, connecting to the network, and controlling via SSH, have already been explained in detail in this guide. Please refer to it if anything is unclear before proceeding with the following steps.

As mentioned earlier, we are using Samba to provide the network directory. The installation is done using the following command lines.

sudo apt-get update

sudo apt-get install samba samba-common-bin

After installation, we are ready to adjust the configuration files and call up “nano” as a text editor for this purpose.

sudo nano /etc/samba/smb.conf

In the file, we look for the following two lines and set the parameters.

workgroup = WORKGROUP
wins support = yes

You can of course set whatever name you want for your “Workgroup”. Workgroup is the parameter that is preset by default on all Windows computers.

Setting up the directory

It’s best to set up the share directory within the home directory of the default user “pi”. If you use a different setup with other users here, you can of course modify this accordingly. First, we make sure that we are in the correct directory.

cd /home/pi

And we create a new directory, here called “pi-share”.

mkdir pi-share

After the directory is created, we can now adjust the Samba configuration.

sudo nano /etc/samba/smb.conf

We scroll to the very end of the configuration file and add the following lines.

[Pi-Share]
comment=Raspberry Pi Share
path=/home/pi/pi-share
browseable=Yes
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=no

Let’s take a closer look at the last line. The default value “no” means that only logged-in users can access our newly created network storage. More specifically, these are users that are set up on your Raspberry Pi (not where the access originates). However, it’s not a problem to log in multiple users using the default “pi” user with the same corresponding password. This also allows us to set access rights individually for each user. The other option would be to simply use “public=yes”, which would mean that user authentication is not required and any computer with access to your home network would have unlimited access to your directory. Please be aware that this poses risks if your home network can somehow be accessed from outside. Normally, you are protected by a router NAT, but there could be other devices in your network that allow incoming connections.

Once we’ve made this decision, we can tell Samba which users should be set up as Samba users for accessing the network drive. By default, we do this with the default Raspbian user “pi”.

sudo smbpasswd -a pi

Then enter the password (for the user pi usually “raspberry”). If you have set up multiple users, simply perform this step accordingly for each additional one.

And voilà, your network storage is fully set up and can already be accessed by other devices in your network using the following connection details:

Domain: raspberrypi
User: pi
Password: raspberry

(or whatever you have alternatively set as username and password)


For Windows 7 / 8 & 10, it's best to use Windows Explorer and the "Map network drive" function.
Netzlaufwerk_verbinden
Connect network drive

Please note that during login we must select a user that is set up on our Raspberry Pi.

Verbinden_als_Benutzer
Connecting as user “pi”

Activating Samba in Windows 10

It has been pointed out in the comments that Samba is disabled by default in current versions of Windows 10. The activation of this setting is very well described on this page.

Fixing Permission Errors with Windows 10

Several readers of this page have already mentioned in the comments that Windows 10 in particular often experiences permission problems and insufficient write permissions with the shared folder. A solution can be to adjust the permissions again using the following command in the Raspberry Pi command line:

sudo chmod -R 777 /home/pi/pi-share/

Further Tips

If you already use your Raspberry Pi as a media server or music server, as linked above, you can also make your music directory accessible via Samba on the network, which of course greatly simplifies populating your media library and establishes interconnectivity with all your other devices such as laptops, smartphones, etc.

Leave a comment