SAMBA-Server – 4 Easy Steps with Raspberry Pi

In today’s time storage is almost a tradable good and we all have seen the infamous No Storage Left message.

And as with everything that people need and/or want businesses profit from it by selling cloud storage or expensive external drives.

What if you could build your very own home server? - You would obviously follow this easy 4 step tutorial on how to configure a samba-server with Raspberry Pi! Click To Tweet

But what if you could build your own home server out of things that you might already have and a few snippets of code? – You would obviously be following this easy tutorial on how to configure a samba-server with Raspberry Pi in four easy steps!

4 Steps

  1. Preparation
  2. Install Samba
  3. Configure external storage
  4. Configure Samba
  5. (Optional) Add Start at boot

Preparation

A wise man once said on the internet:

ALWAYS UPDATE!!!

And he was right – you should always update before starting a new project or working on code since newer versions might change it.
The commands to use are:

This is what it looks like if there are no updates or upgrades to install – so don’t get scared if your output is WAAAAY longer and you are supposed to confirm the download.

Install Samba

Once the preparation is done, we can start with the download of samba.

Samba is the program that will allow your Pi to share a certain path with participants in the network and act as a server

 

Similar to before, this is what it would look like if you had it already installed, so no worries – it will definitely be longer and require confirmation.

Configure External Storage

During this step, we will also create a new path to which we will mount the external storage device – except if you have a 128GB SD card inserted in your Pi or want even more storage.

If you want some more info on the different commands used in this tutorial or The Most Important Linux Commands, I have a guide on that that might help you.

The first command we’ll have to run is fdisk -l
It will list all connected external devices at the bottom of the output and where they are to find – which is what we need to know in order to mount the drive.

Now that we know where to find the drive, let’s mount it.

sudo mount /dev/sda2 /media/server

Configure Samba

Okay, this is the longest and probably most complicated step of the four, but we’ll get through this!

As no one wants to leave their data in the open, we’ll need a password – this can be done by using sudo smbpasswd -a pi
The -a stands for creating a new password and pi is the standard user (but you can add others of course).

Now that we have created the password, we need to tell samba what it is supposed to share and what not, as well as some security stuff.

To do this we’ll have to edit the smb.conf file by using nano.

sudo nano /etc/samba/smb.conf

You’ll have to find this part of the file and set read only to “no”.

Next, we will need to add code in order to tell samba what to do.
Just scroll right to the very bottom and add these lines:

The first paragraph contains our security settings and prevents the login process from crashing.
The second paragraph is about who is admitted, the path and that it can be edited.

To save and close press control + X then Y to agree and Enter to close.

Now you’re basically done, just restart samba in the console and head over to Finder or wherever your network is displayed and log in!

sudo /etc/init.d/samba restart

(Optional) Start at boot

Well, we’re done with the server and can put it somewhere.
But what if you turn it off?
You’d have to go back to the terminal and reactivate it manually.

But isn’t there a simpler solution?

There is!

Crontab!
Crontab? What is that?

The crontab file’s a file to which we can add a line with which’s help our Pi will start samba at boot.

sudo crontab -e

You might have to choose an editor, so choose nano and exit as we have done before.

But that’s sadly the end…

Let’s go and store soma data!

Leave a Reply

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