Raspberry Pi as a Samba server to create a Shared folder between two or more computers.

Victor Fernandez
4 min readApr 12, 2022
Raspberry pi
Photo by Louis Reed on Unsplash

The problem: I have two computers one with access to the internal system and corporate email, the second for testing and coding, From time to time I need to send snapshots from PC-A to PC-B, but I cannot use google drive or dropbox.

The Solution: A shared folder where I can drop files from PC A and retrieve it with PC B.

The Implementation: let's break the solution into software and hardware.

  • For the software, we can use something like Samba.
  • Now for the Hardware, Raspberry pi. I have some pi3, it is cheap, small, and easy to work with.

Steps

  1. “Bake the pi” Install the OS in the Raspberry pi.
  2. Set the samba server.
  3. Connect to the samba server.

1. “Bake the Pi”

The first step will get the OS in the SDcard and onto the pi, there are many tutorials on how to do it, and I will recommend using the Raspberry imager and the Raspberry Pi OS Lite (64-bit).

Raspberry Pi Imager

Samba

It is open-source software, initially designed for Unix/Linux-based systems but it is able to communicate with windows clients. It supports support for several file systems, which makes it perfect for our solution.

I think a NAS will provide more functionalities and higher security, also a NAS might provide access to the directories out of the local LAN in a secure manner.

2. Set the samba server

Initial steps

I do this every time I work with Linux or raspberry pi, and I advise you to do it too.

sudo apt-get update
sudo apt-get upgrade

Next, let’s get samba.

sudo apt-get install samba samba-common-bin

Prepare the shared directory/folder

Now we need to define the folder/directory we are going to use, this will be the folder that PC A and B will have access to.

The folder can be located anywhere, even in an external folder. the SDcard I was using died a few days after and because I set the folder in a thumb drive I didn’t last the information, I just need it to bake another SDCard install samba and I was up and running.

mkdir /home/pi/shared

Access configuration

The next step is to modify the file smb.conf to let samba knows where the folder to share is and how to handle the access.

sudo nano /etc/samba/smb.conf

at the end of the file add:

[pimyshare]
path = /home/pi/shared
writeable=Yescreate mask=0777directory mask=0777public=no
  1. [pimyshare] the text in brackets defines the point where we will access the folder itself, for example //raspberrypi/pimyshare. this will be important later when we configure PC a and B to access the folder.
  2. path is the path to the directory we are going to share.
  3. writeable set as yes allow the user to write in the folder (we need this to add new files to the folder).
  4. create mask and directory mask define the permission for both folder and files, it is set as 07770777 users are allowed to read, write and execute (some cases will be better to avoid the execution for security reasons).
  5. public set to no it will require a valid user to grant access to the folder.

Save the document in this case Ctrl + X and Y .

Set a user for the samba share

To control the access to this folder, I add a user and a password.

With this command we can set the password, the user will be pi

sudo smbpasswd -a pi

Restart the server.

sudo systemctl restart smbd

If we need to get the hostname, we can obtain it with hostname -I .

3. Connect to the Samba server

The final step is to configure access to the shared directory.

Windows

  • File Explorer > Computer > Map network drive
  • Now we need to input the name of the host or the IP address followed by the name of the folder ( name in brackets in the configuration file)

The system will ask you for the user and password, as explained in a previous step the user is “pi” and the password was the one defined before.

Final Thoughts

  • It is a simple and useful project, however, it might not be suitable for cases where several hosts request access.
  • It needs some work in terms of security, but in my case, it is enough since I will be the only one with the password.
  • This can be implemented with raspberry pi zero W with similar results and an even smaller size.

Victor Fernandez

--

--

Victor Fernandez

I’m Victor, I’m a Field Application Engineer for a CCTV manufacturer. I love Raspberry Pi, Python, and Microcontrollers and I write about my personal projects.