Samba

Samba is a common tool for building file sharing and access control services on Linux systems. It uses the SMB protocol to enable file sharing between different devices within a local area network. By deploying Samba locally, you can conveniently provide shared directories to Windows, Linux, or macOS clients, facilitating cross-platform file transfer and collaboration.

This document introduces how to configure the Samba file sharing service on a Debian/Linux system, allowing Windows computers to directly access the device’s shared folders.

Preparation

  1. Confirm the device environment.

    • The device is now able to connect the network normally.
    • The Windows host and the device are in the same local area network.
  2. Check network connectivity.

  • Execute ping www.baidu.com in the terminal. If you can see response time information, it indicates that the network is normal.

Install Samba Service

Samba is a service program used for sharing files with Windows systems on Debian/Linux.

  1. Update the package list:

    sudo apt-get update
    

    This operation ensures the system obtains the latest software source information to avoid the installation of outdated software.

  2. Install Samba and client tools:

    sudo apt-get install samba
    sudo apt-get install smbclient
    

    samba:Server-side software used to provide sharing services.

    smbclient:Client tool used to test whether the connection is successful.

  3. Confirm Samba installation is successful:

    sudo samba -V
    

Create a Shared Folder

  1. Create the shared directory:

    mkdir -p /home/pi/share
    
  2. Create a test file:

    touch /home/pi/share/test.txt
    
  3. Modify permissions:

    chmod -R 777 /home/pi/share
    

Configure Samba Service

  1. Open the configuration file:

    sudo vim /etc/samba/smb.conf
    

    If you are not familiar with vim, you can use other editors such as nano.

    sudo nano /etc/samba/smb.conf
    
  2. Scroll to the end of the file and add the following content:

    [myshare]
        comment = My Shared Folder
        browseable = yes
        path = /home/pi/share
        create mask = 0777
        directory mask = 0777
        valid users = pi
        force user = pi
        force group = pi
        public = yes
        writable = yes
        available = yes
    

    [myshare]----The name of the shared folder as seen by Windows clients when accessing.

    path----The actual path of the shared directory.

    create mask / directory mask----The default permissions for newly created files/folders.

    vaild users ----Legitimate users allowed to access the Samba server. The example user here is pi.

    writable = yes----Allows clients to create, modify, and delete files in this directory.

Set Samba User and Password

Samba login users require a separately set password. Taking the system user pi as an example:

sudo smbpasswd -a pi

Enter the password twice for confirmation (this password will be required when accessing from Windows).

Restart Samba Service for Configuration to Take Effect

sudo systemctl restart smbd

Set Samba to start automatically on boot:

sudo systemctl enable smbd

Check Device IP Address

sudo ifconfig

Access Shared Folder From a Windows Computer

  1. Press "Win+R" to open the Run dialog.

  2. Enter the device’s IP address to see the shared folder.

  3. Enter the username and password to access the contents of the shared folder.

    Username: pi

    Password: The password set using sudo smbpasswd -a pi

After successful access, you can see the previously created test file test.txt.