Create NAS network storage with Raspberry Pi and Samba
Today, TipsMake.com will explain how to create a NAS on a Raspberry Pi using Samba software.
This article will show you how to create a hard drive on a local network with Raspberry Pi and Samba, on which all multimedia devices (computer, TV .) can be accessed without having to connect to it. .
Prerequisites for installing a NAS
Above all, it is important to prepare the necessary things to do this. Obviously you'll need a Raspberry Pi, Ethernet cable, or WiFi dongle if the Pi is older than model 3, the power supply, an SD card with Raspbian installed, and finally one or more hard drives accessible over the network. Prioritize using a hard drive powered through an electrical outlet to reduce the Raspberry Pi's energy consumption.
Configure Raspberry Pi
Once you have all the necessary devices, the Raspberry is running and you are connected in SSH, you can start by updating your Raspberry Pi
sudo apt update sudo apt upgrade
Once the update is complete, create public and private folders accessible on the NAS.
sudo mkdir /home/shares sudo mkdir /home/shares/public sudo chown -R root:users /home/shares/public sudo chmod -R ug=rwx,o=rx /home/shares/public
Create a NAS server with Samba
The basic configuration of the Raspberry Pi is done, you can now install the NAS. For this, we'll use Samba, a piece of software capable of managing network hard drives for access from any operating system or computer connected to the network.
So, we will start by installing Samba on the Raspberry Pi using the following command:
sudo apt install samba samba-common-bin
After that, let's edit the configuration file.
sudo nano /etc/samba/smb.conf
If you want to limit the connection to your NAS by requiring authentication, go to the line
##### Authentication #####
. and add the following line just below:
security = user
To manage your personal storage space, go to [homes]. If you want to be able to write (send files) to your NAS, make sure the file contains the following line:
read only = no
Finally, at the end of the file, let's add parameters regarding access to the public part of the NAS:
[public] comment = public storage path = /home/shares/public valid users = @users force group = users create mask = 0660 directory mask = 0771 read only = no
Close the file by saving it and restarting Samba.
sudo /etc/init.d/smbd restart
Now let's add a user to Samba. In this example user pi will be added.
sudo smbpasswd -a pi
Add a multimedia device
If you want to add a USB or hard drive for more space then obviously, that's possible. To simplify things if you want to connect multiple devices, it is best to connect / configure them one by one.
Start off by connecting the device to the Raspberry Pi. Find out what the device name when connected to Pi is. To do this, execute the command:
dmesg
In the example, the name of the media is sda1 but this could change, especially if you have multiple devices connected.
Be careful, your device must be formatted using the Linux file system, like ext3 or ext4. If not, you can format it using the following command (replace sda1 with your device name, if it's different).
umount /dev/sda1 sudo mkfs.ext4 /dev/sda1
Then create a directory where the device will be mounted for access over the NAS, and then add read and write permissions.
sudo mkdir /home/shares/public/disk1 sudo chown -R root:users /home/shares/public/disk1 sudo chmod -R ug=rwx,o=rx /home/shares/public/disk1
The name of the folder ( disk1 in the example ) doesn't matter, give it the name you want so that it can be easily found on the network. Once done, mount the device to this directory.
sudo mount /dev/sda1 /home/shares/public/disk1
Mount the devices when booting the Raspberry Pi
At this stage of the installation, there's really a problem. Upon restarting the Raspberry Pi, the peripherals will not necessarily mount. To fix this, edit the fstab file .
sudo nano /etc/fstab
And for each device, add the following line at the end of the file (be careful not to confuse the device name and the directory it should be mounted on).
/dev/sda1 /home/shares/public/disk1 auto noatime,nofail 0 0
Connect to the NAS server
My NAS is configured now so next, I will explain how to connect to it. This article will not provide instructions for all operating systems, as the procedure is quite similar. For smartphones, you can connect to an app like File Expert for Android or File Explorer on iOS.
To log in from Windows, go to the This PC window , click the Computer tab , then select Map drive network .
The drive letter doesn't matter, but you do need to know the Raspberry Pi's location on the network, either by its name or the IP address. If you have never changed the name of your Raspberry Pi before, you can connect to a public directory by entering raspberrypipublic or entering a private directory with a username (pi in this example) by entering raspberrypipi.
You should read it
- Samba vulnerabilities allow hackers to invade thousands of remote Linux computers
- How to turn Raspberry Pi into travel router with VPN
- How to create custom shortcut keys for Raspberry Pi
- Hackers start using SambaCry to attack Linux computers
- How to create a Plex Server on Raspberry Pi 4
- How to create a new user in Raspberry Pi OS
- How to make a Raspberry Pi a web server
- How to create a new pool and storage space in Windows 10
May be interested
- How to add an ADC to Raspberry Pi: What you need to knowraspberry pi lacks analog input. this puts it at a disadvantage compared to microcontroller-based boards like the arduino.
- How to create a Plex Server on Raspberry Pi 4plex is a great toolkit, a media server software that allows you to stream movies and tv shows directly to any plex client. learn how to build an independent plex server from your raspberry pi 4 and hard drive.
- Raspberry Pi Zero vs Model A and B, how are they different?you want to buy a raspberry pi, but when you search, you have a problem: why are there so many raspberry pi models? although all of the different raspberry pi can do many similar tasks, there are tasks that specific boards will be more suitable for.
- Samba vulnerabilities allow hackers to invade thousands of remote Linux computersa 7-year-old vulnerability was found on samba software, allowing an attacker to hack and control linux and unix computers remotely.
- How to turn Raspberry Pi into travel router with VPNif you don't have a handy travel router, don't worry. readers can build such a router with raspberry pi. raspberry pi is the perfect choice for traveling homemade vpn routers.
- How to set up Raspberry Pi as a web serverthe raspberry pi line of barebone computers are compact devices that inspire creativity and are almost perfect if you want to create your own server at home.
- Turn your Raspberry Pi into an ad blockerthis article will show you how to convert a raspberry pi into an ad blocker all over the network, using pi-hole. once completed, you will be able to block ads on any device connected to the network.
- Create your own wireless printer with Raspberry Piwireless technology is probably the best improvement for printing for years. fewer, more flexible cables about where you can put your printer, it's great (unless you have an old printer).
- How to set up Tor proxy with Raspberry Piin today's article, you'll learn how to set up a tor proxy on your raspberry pi and use it to automatically route traffic through tor whenever you connect to your home network.
- What is the Raspberry Pi and how is the Raspberry Pi used?you can use the raspberry pi as a computer because everything needed has been built in. its broadcom bcm2835 soc processor includes cpu, gpu, ram, microsd card slot, wi-fi, bluetooth and 4 usb 2.0 ports.