Setup a Samba Server to Share File with Windows Clients
Access files on your Raspberry Pi from Windows clients by using Samba.
- Raspberry Pi discoverable on the network.
- Easily manipulate files from other devices.
This guide is aimed at Raspberry Pis, but will work for any Debian based OS. E.g. Ubuntu 18.04 server, so just use what suits you. I’ve chosen a Raspberry Pi as it makes for a great low power server and a lot of the projects I do require network file shares to be created. For best results connect the Raspberry Pi to the network via ethernet cable.
Note The Raspberry Pi 3B+ has a 300Mb/s ethernet connection, Raspberry Pi 4 Model B has a 1Gb/s ethernet connection.
Samba is a network protocol to allow Windows clients to share files, printers and access other Windows services such as Active Directory.
Click here for a full detailed description of Samba.
SSH stands for secure shell. SSH is an encrypted connection established between two computer programs. On the server side (the computer being connected to) a service is running that listens for another computer trying to contact it via SSH.
Click here for a full detailed description of SSH.
Create a Network Share
First things first, let’s install the packages necessary to run a Samba server:
sudo apt-get install samba -y
Once the package has installed we can configure the Samba server, this is done by editing the smb.conf file in /etc/samba/smb.conf.
Before we configure the server let’s create the folder that will be shared (I’m assuming it’s not already existing, if it exists skip this step). I’m using /mnt/SharedFolder for my file share:
sudo mkdir /mnt/SharedFolder
With having a folder to share we need to make sure the user that will connect to it is the owner. I’m using the user pi for this guide:
sudo chown -R pi:pi /mnt/SharedFolder
The option -R means the chown command is recursive and will update all sub files and folders.
Now we can start editing the config file, but before we make any edits, lets make a backup of the original so we can always roll back:
sudo cp /etc/samba/smb.conf /etc/samba/smb.bak
Now to update smb.conf:
sudo nano /etc/samba/smb.conf
We’re going to enable WINS (Windows Internet Name Service) support.
Look for the line:
# wins support = no
And replace it with:
wins support = yes
Now to setup the Samba share, but before we do, let’s look into some of the options below.
- path – This is the path to the folder you’re going to be sharing.
- force user – This is the username that everything will be stored as. I’m going to use pi for this guide.
- valid users – This is a comma separated list of users that are allowed to access the samba share.
Now we know what we’re doing go to the end of the file and paste the following:
[SharedFolder] #This is the name of the share it will show up as when you browse comment = Finished Torrents Folder path = /mnt/SharedFolder create mask = 0775 directory mask = 0775 read only = no browseable = yes public = yes force user = pi valid users = pi only guest = no
Press Ctrl+x to exit and you’ll be prompted to Save modified. Type Y and then return to save the file.
We need to set a samba (memorable and secure) password for qbtuser, this will be used to connect to the share:
sudo smbpasswd -a pi
Now we’ve finished setting it up lets restart the samba service:
sudo service smbd restart
Once the service has restarted let’s try and connect. If this fails, reboot your Raspberry Pi to ensure all settings have been updated.
The Raspberry Pi should be visible on your Network tab, but you can directly navigate to it using either the hostname or IP address of the Raspberry Pi in the address bar of a file explorer window:
On the first time logging in you’ll need to provide the user details.
- username: pi.
- password: *Setup earlier*.
Ticking Remember my credentials means you won’t have to go through this process each time you try to access the Raspberry Pi’s file share.
It’s not recommended to remember credentials on a shared computer as anyone will be able to access the share.