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
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
Check network connectivity
- Run
ping www.baidu.comin the terminal. If time information is returned, it indicates that the network is functioning normally.
- Run
Install the Samba Service
Samba is a service program on Debian/Linux used for sharing files with Windows.
Update the package list
sudo apt-get updateAllow the system to obtain the latest software source information to avoid installing outdated versions.
Install Samba and client tools
sudo apt-get install samba sudo apt-get install smbclientsamba:Server-side component used to provide file sharing services.smbclient:Client tool used to test whether the connection is successful.Confirm that Samba is installed successfully
sudo samba -V
Create a Shared Folder
Create the shared directory
mkdir -p /home/pi/shareCreate a test file
touch /home/pi/share/test.txtModify permissions
chmod -R 777 /home/pi/share
Configure the Samba Service
Open the configuration file
sudo vim /etc/samba/smb.confIf you are not familiar with
vim, you can use other editors such asnano.sudo nano /etc/samba/smb.confScroll 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 seepath----The actual path of the shared directorycreate mask / directory mask----Default permissions for newly created files/foldersvaild users----Authorized users who can access the Samba server; in this example, the user ispiwritable = 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
Press Win+R to open the Run dialog.
Enter the device’s IP address to see the shared folder.
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.
