Skip to content

NAS setup with Samba

Samba is an implementation of SMB (Server Message Block) protocol. It allows Linux machines to integrate Microsoft’s active directory.

CIFS (Common Internet File System) is an implementation of the SMB protocol. CIFs or SMB is used interchangeably nowadays, but most people will use the term SMB. By using Samba on the Raspberry Pi, you can easily share directories in a way that they can be accessed on almost every operating system.

Install the following apt libraries:

Terminal window
sudo apt install samba samba-common-bin

Create a directory to share:

Terminal window
mkdir ~/shared

You could also attach an external diver to the Raspberry Pi, and point Samba to that drive.


Then edit smb.conf file:

Terminal window
sudo nano /etc/samba/smb.conf

Add this at the bottom of the file:

[myshared]
path = /home/pit/shared
writeable = yes
browseable = yes
public = no

Let’s analyze the content of the configuration:

  1. [myshared]: this block defines the start of a new Samba share. The text between the square brackets ([...]) is the name that will be assigned to your share. You should access this by going to: \\192.168.xxx.xxx\myshare.
  2. path use this option to specify the path of the directory you want to share using Samba on your Raspberry Pi.
  3. writeable: when the option is set to yes, it will allow the folder to be writable. If you want to block users from being able to write to this share, set this to no.
  4. browseable: allows you to control whether this share will be viewable by others on your network. Setting this option to yes will allow others to find this share on your network. By setting this option to no, you will be required to enter the share path to connect to it.
  5. public: if this is set to no, the Pi will require a connection to have a valid user to access the Samba share.

Next, set up a user for your Samba share on the Raspberry Pi. Without it, we won’t be able to make a connection to the shared network drive.

To assign a Samba password to your user, you need to utilize the smbpassword tool. Use the command below to set a password for your current user:

Terminal window
sudo smbpasswd -a $(echo $USER)

It will prompt you to enter the password.


Restarting Samba on your Raspberry Pi:

Terminal window
sudo systemctl restart smbd

To connect to your Samba on Windows, open File Explorer. Click the Computer tab, then click Map network drive.

Within the Folder textbox, enter the following \\192.168.xxx.xxx\myshare. Replace 192.168.xxx.xxx with the actual address of the Raspberry Pi. Once done, click the Finish button to finalize the connection.

Eventually, you will be asked to enter your login details to be able to finish the connection. Enter the username and password you set using the smbpasswd tool earlier on in the tutorial.

Once done, click the OK button to continue.


That’s it! You’re now connected to your Raspberry Pi-powered NAS.

Links used: