Samba

This article 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 can connect to the network normally
    • The Windows computer and the device are in the same local area network
  2. Check network connectivity

    • Run ping www.baidu.com in the terminal. If time information is returned, it indicates that the network is functioning normally.

Install the Samba Service

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

  1. Update the package list

    sudo apt-get update
    

    Allow the system to obtain the latest software source information to avoid installing outdated versions.

  2. Install Samba and client tools

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

    samba:Server-side component used to provide file sharing services.

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

  3. Confirm that Samba is installed successfully

    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 the 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 shared name that Windows will see

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

    create mask / directory mask----Default permissions for newly created files/folders

    vaild users ----Authorized users who can access the Samba server; in this example, the user is pi

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

Set Samba User and Password

Samba login users need to have a separate password.
Here, the system user pi is used as an example:

sudo smbpasswd -a pi

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

Restart the Samba service to apply the configuration

sudo systemctl restart smbd

Enable Samba to start automatically at boot.

sudo systemctl enable smbd

Check the device’s IP address

sudo ifconfig

Access the 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

Once inside, you can see the previously created test file test.txt.