A couple of weeks ago, my Macbook suddenly crashed and I lost some important data in it. At that time, I really wished that I have a NAS or Network Attached Storage, so I can simply backup my data and retrieve it when I need it. Also, I was having an external 1 TB hard-drive. It is a great opportunity to both experiment and make something useful with Raspberry Pi. So, I decided to make a NAS with my Raspberry Pi and Samba server.

Starting with the Basics

Let’s start with the basics. It’s very important that when you logged in to pi user, change the default password first. User passwd command and change the default password.

pi@raspberrypi:/home $ passwd
Changing password for pi.
Current password:
New password:
Retype new password:
passwd: password updated successfully

Now, let’s update and upgrade everything in the our pi.

pi@raspberrypi:/home $ sudo apt-get update -y && sudo apt-get upgrade -y

This will take some time, don’t worry. When it finishes, reboot the device and reconnect.

pi@raspberrypi:/home $ sudo reboot 

Also, let’s get our IP address, we will need this to connect from other devices.

# If you are using Ethernet connection in Raspberry Pi, use eth0 or if you are using Wi-Fi, use wlan0 
pi@raspberrypi:/ $ ifconfig eth0 | grep inet
        inet  netmask  broadcast
# Great, we got our IP address!

Installing the necessary packages

We need to install samba and its utilities and according to your hard-drive, you need to install support packages for it.

pi@raspberrypi:/home $ sudo apt-get install samba samba-common-bin -y
# For ExFAT
pi@raspberrypi:/home $ sudo apt-get install exfat-utils exfat-fuse -y
# For NTFS
pi@raspberrypi:/home $ sudo apt-get install ntfs-3g -y

Mounting the hard-drive

In order to use our hard-drive in local file system, we need to mount that drive to a folder. So, let’s create a folder to mount.

pi@raspberrypi:/ $ mkdir nas && sudo chmod 750 nas/
pi@raspberrypi:/ $ ls
bin   dev  home  lost+found  mnt  opt   root  sbin  sys  usr
boot  etc  lib   media       nas  proc  run   srv   tmp  var

We can see our freshly created “nas” folder, great! Let’s mount the hard-drive to that folder. First let’s find our hard-drive.

pi@raspberrypi:/ $ lsblk
sda           8:0    0 931.5G  0 disk
└─sda1        8:1    0 931.5G  0 part 
mmcblk0     179:0    0  14.4G  0 disk
├─mmcblk0p1 179:1    0   256M  0 part /boot
└─mmcblk0p2 179:2    0  14.2G  0 part /
# For me it's located at /dev/sda1. So let's mount it to /nas
pi@raspberrypi:/ $ sudo mount /dev/sda1 /nas
# Also let's configuring our mounting point as auto-mount. So it'll also work after rebooting as well.
pi@raspberrypi:/ $ sudo nano /etc/fstab
# Add the line below at the bottom of the file
# /dev/sda1 /nas auto defaults, user 0 2

After this step, if you go to /nas folder, you should be able to see the contents of hard-drive.

Configuring Samba Server

We need to configure our samba server in order to access it. So, let’s go the config file and edit the values for our needs.

pi@raspberrypi:/ $ sudo nano /etc/samba/smb.conf
# Then add these values add the end of the file
[NAS Server]
   comment = "NAS"
   path = /nas
   read only = no
   writable = yes
   browsable = yes
   create mask = 0750
   directory mask = 0750
   public = no
   force user = samba

Great! Now, let’s add a samba user and let’s assign that user to use our samba server from other machines.

pi@raspberrypi:/ $ sudo adduser samba
# After creating our user, let's add this user as samba user as well. Remember this password, we need to connect to server afterwards.
pi@raspberrypi:/ $ sudo smbpasswd -a samba
New SMB password:
Retype new SMB password:
Added user samba.
# Finally, let's restart our services.
pi@raspberrypi:/ $ systemctl restart smbd
pi@raspberrypi:/ $ systemctl restart nmbd

All done!

Connecting the server

From Mac

Go to “Finder” and press “cmd + K”. Then write “smb://” and press “Connect”. Then select the “NAS Server” and you should see it on your Finder.

From Windows

Go to “File Explorer” and write “\\” at the top bar. You should see the “NAS Server”. Right click and press “Map network drive..” Then, write the username and password of “samba” user and you should be good to go!

Closing notes

I hope you liked what you read and I am really looking forward to seeing you in the next one! If you don’t want to miss any content, you can subscribe to the website and I will let you know whenever something new going on here!

Also you can reach out to me from the “Contact” section. Feel free to share your thoughs or suggest any ideas. I am reading all the messages and I will reply yours as soon as possible!

As you might know me, I like coffee and high-quality content. If you want to support me and my effort, why not a little caffeine boost ha? 😎

Buy Me A Coffee

Until next one,