Raspberry Pi NAS (Samba + FTP+ DLNA)

Connect your drive

The best way to safely and conveniently access your drive from various devices is to create a dedicated user and mount your drive into that user home directory.

Add a user named mediaserver with his home directory and set password:

sudo useradd -m mediaserver
sudo passwd mediaserver

Create ssd directory:

mkdir /home/mediaserver/ssd

List connected drives:

lsblk

You should see something like that:

[~]$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 238.5G  0 disk
├─sda1        8:1    0   500M  0 part
├─sda2        8:2    0 144.9G  0 part
├─sda3        8:3    0     4G  0 part
└─sda4        8:4    0  89.1G  0 part
mmcblk0     179:0    0    29G  0 disk
├─mmcblk0p1 179:1    0   256M  0 part /boot
└─mmcblk0p2 179:2    0  28.7G  0 part /

In my case I want to use partition sda2 as shared drive.

Ensure that the drive is mounted after each boot:

sudo nano /etc/fstab

Add the following line at the end of the file:

/dev/sda2 /home/mediaserver/ssd ntfs-3g defaults,noatime 0 1

Mount drive in mediaserver home dir:

sudo mount /dev/sda2

Samba

Install Samba service if you want to access your data as a network share in Windows.

Install samba, set password for user mediaserver and edit configuration file:

sudo apt update
sudo apt-get install samba samba-common-bin
sudo smbpasswd -a mediaserver
sudo nano /etc/samba/smb.conf

And add the following line at the end of the file:

[global]
allow insecure wide links = yes

[mediaserver]
path=/home/mediaserver/ssd
writeable=Yes
create mask=0777
directory mask=0777
public=no
follow symlinks = yes
wide links = yes

Restart Samba to load the configuration changes:

sudo systemctl restart smbd

FTP server

Install an FTP server if you want to access your drive via FTP, e.g. from a smartphone or the Internet after setting up a firewall.

Install FTP server:

sudo apt update
sudo apt-get install vsftpd

Edit vsftpd conf file:

sudo nano /etc/vsftpd.conf 

With:

write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES

# Turn on passive mode!
pasv_enable=Yes
pasv_max_port=10100
pasv_min_port=10090

# Enables only certain users!
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO

Make user list:

sudo nano /etc/vsftpd.userlist

In the file, enter the list of users who will have access to FTP (EOL separated).

Restart service:

sudo systemctl restart vsftpd.service

Tip: By default, all newly created Linux users have access to their accounts via FTP. You can change this by creating a black/white list.

DLNA server

Install a DLNA server if you want to stream media from your hard drive to devices such as Smart TV.

sudo apt update
sudo apt-get install minidlna

Edit configuration file to set up media directories:

sudo nano /etc/minidlna.conf

With:

media_dir=V,/home/mediaserver/ssd/Movies
media_dir=A,/home/mediaserver/ssd/Music
media_dir=P,/home/mediaserver/ssd/Zdjęcia

Restart service and recreate database:

sudo service minidlna restart
sudo service minidlna force-reload

Most of smart devices will automatically recognize you service. If not, you can access your DLNA server on port 8200 (http://xxx.xxx.xxx.xxx:8200).

If you want to access some of your services from the Internet, you need to have a static IP address and forward the service ports on your router. Remember to configure your firewall and FTP access before!