Samba
Samba is a protocol that allows access to a folder located on a network drive. It can be configured on macOS, Windows, or Linux.
There are many tutorials for setting up Samba on Windows or on NAS systems like Synology, but here we focus on Debian.
Create and configure a Shared Network Folder
/video folder from a remote machine called remote-machine. We will access this folder from a machine called local-machine. The user connecting to the network drive will be sambauser.Install Samba Server
sudo apt update && sudo apt upgrade
sudo apt install samba smbclient cifs-utils
Create the /video Folder
sudo mkdir /video
Configure the Share
Now, edit the file /etc/samba/smb.conf.
sudo nano /etc/samba/smb.conf
Find the workgroup variable and name your workgroup (e.g., workgroup = WORKGROUP).
Then scroll to the end of the file and add the following configuration:
[video]
comment = Video folder
path = /video
writable = yes
guest ok = no
valid users = @smbshare
force create mode = 770
force directory mode = 770
inherit permissions = yes
Press Ctrl+O, then Enter to save, and Ctrl+X to exit.
Done !
Create a Samba User and Group
Since we're using a secured share, we need to create a user and group to access it remotely.
Create the group
sudo groupadd smbshare
Give the group control over the /video folder:
sudo chgrp -R smbshare /video
Set inherited permissions:
sudo chmod 2775 /video
Create the user
Now add a no-login user: this user cannot log into the server but can access Samba.
sudo useradd -M -s /sbin/nologin sambauser
Add the user to the smbshare group:
sudo usermod -aG smbshare sambauser
Set a Samba password:
sudo smbpasswd -a sambauser
Enable the Samba account
sudo smbpasswd -e sambauser
Done !
Accessing a Shared Folder
Install Required Packages
sudo apt update && sudo apt upgrade
sudo apt install cifs-utils
Create the Mount Destination
We will create a folder on our local machine where the remote /video folder will be mounted, e.g. /mnt/video.
sudo mkdir /mnt/video
Prepare the .credentials File
To avoid typing our username and password every time, create a .credentials file storing the login info.
Create it in the /smb folder:
sudo mkdir /smb
sudo nano /smb/.credentials
Write:
username=smbuser
password=password
smbuser: the user we created on theremote-machinepassword: the password set earlier
Press Ctrl+O, then Enter to save, and Ctrl+X to exit.
Set proper file permissions:
sudo chmod 600 /smb/.credentials
Mount the Shared Folder
sudo ufw allow from <your-remote-ip> to any app Samba
Now mount the folder:
sudo mount -t cifs -o credentials=/smb/.credentials //remote-ip/video /mnt/video
Replace remote-ip with your remote-machine's IP address.
Verify the mount:
sudo mount -t cifs
You’ll see details confirming the mount is successful.
Now you can access the /video folder of the remote-machine from your local-machine!
(Optional) Auto-mount on Boot
By default, shares aren't auto-mounted after reboot. To automate this, edit the /etc/fstab file.
First, back it up:
sudo cp /etc/fstab /etc/fstab.bak
Then add the mount configuration line:
sudo echo //remote-ip/video /mnt/video cifs _netdev,nofail,credentials=/smb/.credentials,x-systemd.automount,x-systemd.device-timeout=15 0 0 >> /etc/fstab
Reboot the machine:
sudo reboot
After rebooting, verify the mount:
sudo mount -t cifs
And done!
sudo umount -t cifs /mnt/video