The files in raspberry pie are often expected to be shared in the LAN, such as downloaded videos or hard coded code. Here we can achieve this goal through Samba.
Installing Samba
The installation of samba is very simple. The command line is executed:
sudo apt-get install samba samba-common-bin
Configure Samba
The configuration file is /etc/samba/smb.conf
, modify it here, and execute the command line:
sudo nano /etc/samba/smb.conf
Note: nano can turn pages through ctrl+y (previous page) and ctrl+v (next page).
Add the following content at the end of the file, where/mnt/udisk is the shared folder directory I set (just replace it with the directory you want to share, for example:/home/pi/public):
[public] comment = public storage path = /mnt/udisk valid users = pi read only = no create mask = 0777 directory mask = 0777 guest ok = no browseable = yes
Save with ctrl+o, press Enter to confirm, and then exit with ctrl+x.
Parameter description:
- Comment: Shared folder description
- Path: Shared folder directory
- Valid users: valid users
- Read only: Read only
- Create mask: permission to create files
- Directory mask: permission to create a folder
- Guest ok: Allow visitors to access
- Browseable: Visible
Where, valid users, that is, pi, are valid users, and they need to be added to Samba. Command line execution:
sudo smbpasswd -a pi
Restart samba for effective configuration, and execute the command line:
sudo samba restart
Note: Samba starts automatically by default, so there is no need to worry about restarting.
set files permissions
After setting permissions in the Samba configuration file, you also need to set the permissions of the shared folder in the system to the same permissions as those in the configuration file to ensure that other users can access and modify the folder contents normally. The command line executes:
sudo chmod -R 777 /mnt/udisk
Access shared files
Windows:
In the Explorer address bar, enter: \\192.168.1.37\public
, where 192.168.1.37 is replaced by the IP address of your raspberry pie.
macOS:
Open FINder, and then use the shortcut key cmd+k to fill in the server address smb://192.168.1.37/public
, where 192.168.1.37 is replaced by the IP address of your raspberry pie, and then click Connect.