On the previous post, we installed a new Raspberry Pi 3, we enabled SSH connection and set up wireless connectivity. Today, we’re going to set up Samba file sharing in the Raspberry Pi to manage folders and files from another computer. You can also mount a hard drive to the Pi and set it up as a Network-attached storage, (NAS) so you can share data with all or some devices connected to your network.
First, check and install the latest packages for the Raspberry Pi. Open PuTTY, log into your Pi and then enter the following commands:
sudo apt-get update && sudo apt-get upgrade
After making sure that all packages are up to date, we can now install Samba using the following command:
sudo apt-get install samba samba-common-bin
Step 3 (Optional)
If you don’t want to share all folders and files in the Raspberry Pi, you can create a shared folder using the following command:
I will cover this more in detail in a future post where we’ll mount a hard drive to set up a NAS (Network-attached storage). For now, we are just going to set up Samba to share all directories in the Raspberry Pi.
Now, we need to configure Samba to share the Raspberry Pi directories with another computer within the network. Enter the following command:
sudo nano /etc/samba/smb.conf
The Samba configuration file is well documented. You can scroll down the file to see what you would like to enable. You can also remove everything by pressing and holding
Ctrl and the Letter
K or just copy and paste the following code at the bottom of the file:
[global] netbios name = Pi server string = The Pi File Center workgroup = WORKGROUP [HOMEPI] path = /home/pi comment = No comment writeable=Yes create mask=0777 directory mask=0777 public=no
Here is a short explanation of what the code above means:
workgroup: This is the domain that the Samba server will be part of. By default, Windows has the workgroup set as WORKGROUP
path: This is the path to the directory in the Raspberry Pi that will be shared
writeable: If set to yes, it will allow the folder to be writeable
directory mask: When set to 0777 allows the user to read, write and execute
public: If set to no, it will only allow valid users to access the shared folder
After you enter the above information press and hold
X and press
Y to save the changes.
Right now, we only have the user Pi setup in the Raspberry Pi. We now need to add Pi as a Samba user. Enter the following command:
sudo smbpasswd -a pi
Enter a new password when prompted. You can use the same password as your Raspberry Pi user but for security, enter a different password.
Last but not least, restart the Samba service using the following command:
sudo service smbd restart
OK, so Samba is now configured. You can open the Windows File Explorer and click on Network to access the Raspberry Pi shared folder. When you click on the folder, you will be asked to enter your credentials. Enter the Pi’s username and then the Samba password that you created for that user. After you log in, you will be able to manage the Pi’s folders and files.