Language: EN

compartir-ficheros-en-raspberry-pi-con-samba

Share files with Windows from Raspberry Pi

Let’s see how we can configure your Raspberry Pi as a file server using Samba, so that other Windows computers on the same network can access the shared files.

Samba is a software suite that provides file and print sharing services for Unix/Linux operating systems, using the SMB/CIFS protocol.

SMB/CIFS (Server Message Block/Common Internet File System) is the protocol that Windows uses to share files, printers, and other resources on a network.

Some of the main features of Samba are:

  • Interoperability: Allows Unix/Linux systems to share files with Windows machines.
  • Active Directory compatibility: Can integrate into Active Directory domains.
  • Security: Supports authentication and granular access control.
  • Configurability: Highly configurable to suit various network needs.

Installing Samba on Raspberry Pi

Before installing Samba, it is recommended to update the operating system to ensure you have the latest versions of all packages. Open a terminal and run:

sudo apt update
sudo apt upgrade

Now, we install Samba and its related utilities with the following command:

sudo apt install samba samba-common-bin

You can verify that Samba has been installed correctly by checking its version:

smbd --version

You should see the version of Samba that has been installed.

Configuring Samba

Once installed, you need to configure Samba to share files on your local network. The first step is to create a directory that you want to share on your network.

For example, you can create a directory called shared in your home directory:

mkdir ~/shared

Now we must configure Samba to Share the Directory. We edit the Samba configuration file, smb.conf, to add your new shared resource:

sudo nano /etc/samba/smb.conf

Add the following lines to the end of the file to configure the shared resource:

[shared]
   path = /home/pi/shared
   available = yes
   valid users = pi
   read only = no
   browsable = yes
   public = yes
   writable = yes

These options configure the shared resource shared:

  • path: The path of the directory to share.
  • available: Indicates whether the resource is available.
  • valid users: Specifies which users can access the resource.
  • read only: Allows or disallows writing to the resource.
  • browsable: Makes the resource visible on the network.
  • public: Allows access without authentication.
  • writable: Allows writing to the resource.

Now we need to create a Samba user so that they can access the shared resource. You can use the user pi, or create a new one:

sudo smbpasswd -a pi

It will prompt you to enter and confirm a password for the Samba user.

Finally, to apply the changes, we restart the Samba service:

sudo systemctl restart smbd
sudo systemctl restart nmbd

Connecting to the shared folder

Connecting from Windows

To access the shared resource from a Windows machine:

  1. Open File Explorer.
  2. In the address bar, type \\raspberrypi\shared or \\<IP of your Raspberry Pi>\shared.
  3. Enter the Samba user credentials (for example, pi and the password you configured).

Connecting from Linux

To access the shared resource from a Linux machine:

  1. Open the file manager.
  2. In the address bar, type smb://raspberrypi/shared or smb://<IP of your Raspberry Pi>/shared.
  3. Enter the Samba user credentials.