Setting up SMB share on Raspberry PI | Raspberry PI home server series | Article 3

This is the third article in the Raspberry PI home server series. Check out other articles in this series.

Astitva Sood
4 min readAug 7, 2021
  1. Installing docker on Raspberry PI.
  2. Setting up static IP on Raspberry PI.
  3. Setting up SMB share on Raspberry PI.
  4. More to come ;).

SMB, or Server Message Block, is a client-server communication protocol used to share access to directories, printers, serial ports, and other resources on a network.

In this article, we will be focussing on setting up an SMB share for your local network. We will create 2 shares, one which will be open to everyone on the network, and another which is password protected.

Prerequisites:

  1. OS: Raspberry Pi OS, or any other Debian based Linux distro
  2. Static private IP on SMB server

If you are unsure of how to set up static IP on a Linux machine, visit this article.

Steps:

  1. System update and upgrade
  2. Install required packages
  3. Make share directories
  4. Edit the configuration file
  5. Add SMB user
  6. Restart SMB daemon
  7. Test

1. System update and upgrade

The first step is to update the apt repositories and upgrade the installed packages to their latest version. For this, open the terminal and run the following commands.

sudo apt-get update && sudo apt-get upgrade

2. Install required packages

Now that our PI has been upgraded, we need to install 2 packages, samba and samba-common-bin. This can be done by running the following commands in a terminal.

sudo apt-get install samba samba-common-bin

3. Make share directories

Now, we will create 2 directories, one for our public share, and another for our private share.

Run the following commands in terminal

mkdir /home/<username>/shared                //for private sharesudo mkdir -p /var/public/share              //for public share

If you don’t know your username, run the command

whoami

4. Edit the config file to configure shares

Open the file /etc/samba/smb.conf in your favorite text editor, scroll to the bottom, and add the following lines.

[piprivateshare]path = /home/pi/sharedwriteable=Yescreate mask=0777directory mask=0777public=no[pipublicshare]path = /var/public/sharewriteable=Yescreate mask=0777directory mask=0777public=yes

Details
path: Path to a directory on your raspberry pi that you want to share
writable: Gives the write permission on the directory
create mask: Permission level on the directory
directory mask: Permission level on the directory
0777: Read, write and execute permission on the directory.
public: If set to no, it will require a valid user to grant access.

5. Add SMB user

Now, you would be able to access the public share but to access the private share, you would need to add a user to SMB. To add the user, run the following command:

sudo smbpasswd -a pi

This will add pi as an SMB user.

Note that pi must already be a user on raspberry pi for this to work.

If you are unsure how to add a user, follow this guide

6. Restart SMB daemon

Now that the SMB user is added, the last step is to restart the SMB daemon for changes to be reflected. To restart the SMB service, run the following command in the terminal:

sudo systemctl restart smbd

7. Test connectivity

Now we will try to connect to our SMB share from another machine. The first thing we need to do for testing the connectivity is to get the IP address of the SMB machine. Run the following command in the terminal to get the IP:

hostname -I

Now, we will go to another machine on the same network and try to connect to our SMB share. For demonstration, I am going to show the steps for a mac.

1. Open a finder window and press ⌘+k to connect to a server.

2. Enter the IP address of the server (raspberry PI) in the following format:
smb://<IP>

3. Choose to connect as a guest, or as a registered user.

4. Add username and password in case you are trying to connect as a registered user

5. You would be able to see the smb shares now.

--

--