Code Done Right!

Samba server

Samba server allows you to set up a NAS – Network Attached Storage. This is basically a hard drive (or drives) on your local network that can be accessed by any device connected to your router. You can use it as any other drive or folder on your PC. You can even set up your torrent client to download files there directly! Maybe you swapped HDD in your laptop for an SSD and had no idea what to do with the drive? Set up a samba share on it and give it a second life. Why throw it away if it can be reused?

Unless specified directly, all commands should be executed on your Raspberry server.

Installing Samba

Installing Samba server is a pretty easy task, just run the following command

sudo apt install samba

As usual, a lot of dependancies will be installed as well, not only the samba package.

When asked Modify smb.conf to use WINS settings from DHCP? just say No.

Opening ports

If you have UFW installed, which you should if your Raspberry is open to the internet, you need to open the following ports on your Pi in order to access your resources

  • 139
  • 445

Check back here for a refresher on blocking and opening ports on your server.

Preparing Samba share folder

In order to share anything, you need to have a folder for files. You can create your share folder anywhere in your system. Root forder / or /var/ are a good place to make a directory for sharing. I have chosen the root folder for my shares. Run the following commands

sudo mkdir /samba
sudo chmod 777 -R /samba

You can reuse an existing folder as well, but bear in mind that you will need to chmod it to 777 in order to be able to read and write using other devices.

Mounting an external disk

If you want to utilize an external drive you can do so as well. This actually should be the main reason for setting up a Samba share. Remember that some disks require external power supply. The easiest way is to use a 2.5″ disk in a case. With a proper one you should not need any additional power, be it for an SSD or HDD. Unfortunately you have to test it yourself.

Check out Mounting external drives tutorial to learn how to mount a drive. Substitute the default folder in tutorial with /sabma folder used above, or any other that you have chosen

Modify Samba config file

You will find the config in the following location


At the very bottom add the following code

Comment = Your Samba share
Path = /samba
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes

The above code will add a share named RaspberryPiSamba, modify Path variable in accordance with the place where you mounted your external disk in the above step.

If you want to add another share just add another block like the above, modifying the name in square brackets (it has to be a unique entry) and the path to your share.

Samba MAN page

For a more detailed description of settings check the smb.conf man page. It is a long read, unless you need a specific option or are curious you can leave that for later.

Rebooting Samba server

After making any changes you need to reboot Samba, use the following code

sudo service smbd restart

Your share should be ready and possible to access via local network.

Enabling shared file discovery on Windows

In order to find your Samba share on your Windows 10 you need to enable SMB/CIFS protocol.

Navigate to Windows Settings, click on Applications and functions, now find Programs and features in the upper right corner. A new window will be opened, you might know it as Add and remove software from older Windows versions. Left hand side contains the following entry Turn Windows Features On or Off, click on it and another window will open.

Look for SMB 1.0/CIFS File Sharing Support, if you have a sumbenu with different components then it is enough to enable client only. Tick the box, click on OK and reboot your PC.

Finding your shared folder

The last step is finding your share. Open This PC, and navigate to Network. Or just open Network if present on your desktop. After a brief moment you should be able to find your Raspberry server there. It might require a folder refresh or two.

If you are unsure about the name of your device run the following commands on your Raspberry

hostname -s

It will most likely be visible under one of the names produced by the above command.

Mounting your share permanently in Windows

It is also possible to mount the share, so it is accessible just like any other disk or partition on your system. In order to do so

  • Right-click on This PC icon
  • Select Map network drive…
  • Select drive letter you wish to use for your share
  • Click on Browse button to navigate to your share on your local network
  • Tick Reconnect at sign-in box
  • Click on Finish

Now you should be able to see your share mounted every time you open Windows! Bear in mind that every PC user will have to mount the share if they wish to use it. This is, however, a one-time only procedure.

Accessing share with other devices or software

Your share can be accessed not only by your Windows PC. Your phone or tablet can use it as well but it will require some additional software. Browse Play Store to find something you like, search for samba client.

VLC on the other hand can utilize network shares without the need for any additional software. You can store movies or music on your network drive and stream it to VLC directly. Just browse Local network instead of folders!

Using Samba share with Mac is possible as well, but since I do not own, nor do I plan to own a Mac there will be no guide for it.

Adding password to a samba share

If for some reason you want to add a password for samba shares use the following command

sudo smbpasswd -a $USER

Substitute $USER with a desired username for your shares. Afterwards you will be prompted to set up a password.

Now restart your samba service.

Samba user is different from your system user. Set up whatever you like. You can even reuse your system password and username if security is of no concern due to your server being open to local network only.


Creating a Samba share is quite easy and useful if you want to set up a backup for your files, or just want a remote place to store media. Remember that you can set up as many shares as you want. Mounting ten 1TB disks is quite possible provided you have a USB hub and some additional power flowing to those disks.

Sharing users’ home folders and printers is also possible. Look around for a tutorial on that if you are interested. As I am not, there will be no guide for that here.

Feel free to leave a comment below if you have any questions or found a bug

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.