Samba¶
Samba is a free software implementation of the SMB networking protocol, and was originally developed by Andrew Tridgell.
Server Message Block (SMB) enables file sharing, printer sharing, network browsing, and inter-process communication (through named pipes) over a computer network.
I am primarily using Samba as my local file sharing as NFS causes issues with MergerFS, which is what my NAS uses. Samba also allows for easy sharing across Linux and Windows devices. Outside of these 2 issues, NFS is excellent, but Samba just works better in my situation.
How my NAS shares files¶
Two shares, both on the mergerfs pool, both for one user account:
| Share | Path on the NAS | Used by |
|---|---|---|
shared |
/mnt/storage/shared |
General file dump: the desktop, the other servers |
media |
/mnt/storage/data/media |
The media library, so the desktop can add and tidy files |
Everything else in smb.conf is Debian's stock file (the [global] defaults plus the stock [homes] and printer
sections). Shares point at the pool (/mnt/storage/...), never at a single branch disk, so files written over
SMB follow the mergerfs create policy like everything else.
Who mounts them:
- The desktop mounts both at
/mnt/sharedand/mnt/media: see Mounting NAS shares on a desktop. - The other servers mount
sharedwith systemd automount options, so a NAS that is down or still booting can't hang their boot (see Network mounts that fail at boot). Containers don't depend on it.
Installation¶
This is for creating a share on a NAS, then sharing that as a mount to other machines.
Server install (on NAS)¶
Server install (Debian 13 ships Samba 4.22)
sudo apt update && sudo apt install samba -y
Client tools (smbclient, handy for testing on the server too)
sudo apt install smbclient -y
Confirm it is running:
sudo systemctl status smbd
Create the dir to be used
sudo mkdir -p /mnt/storage/shared
Change ownership
sudo chown <YOUR_USER>:<YOUR_USER> /mnt/storage/shared
Edit the samba config
sudo nano /etc/samba/smb.conf
Add these blocks to the bottom (this is what my NAS runs, with the user name swapped out):
[shared]
path = /mnt/storage/shared
browseable = yes
read only = no
valid users = <YOUR_USER>
[media]
path = /mnt/storage/data/media
browseable = yes
read only = no
valid users = <YOUR_USER>
Limit who can reach Samba
Samba listens on every interface by default. On a server with several networks (VLANs, Docker bridges, a
VPN/tailnet interface) it's good practice to restrict it in [global] to the LAN you actually mount from, on top
of firewall rules:
[global]
hosts allow = 127.0.0.1 <YOUR_SUBNET>
interfaces = lo <YOUR_LAN_INTERFACE>
bind interfaces only = yes
server min protocol = SMB3
Run testparm afterwards and test from every client before you walk away.
Save and exit. Then set a samba password for your user.
sudo smbpasswd -a <YOUR_USER>
Check the config, then restart to apply it
testparm -s && sudo systemctl restart smbd
Verify share is visible
smbclient -L localhost -U <YOUR_USER>
Mounting to machine¶
First, install the CIFS utilities on the machine
sudo apt install cifs-utils -y
Create mount point
sudo mkdir -p /mnt/shared
Now create a credentials file so the password isn't in fstab.
Add:
Lock down permissions.
sudo chmod 600 /etc/samba/credentials
Add the mount to fstab
Add this line at the bottom. Use the hostname, and _netdev so the system waits for the network before mounting:
//<NAS_HOSTNAME>/shared /mnt/shared cifs credentials=/etc/samba/credentials,uid=<PUID>,gid=<PGID>,iocharset=utf8,_netdev 0 0
On a server, add automount options so a NAS that's down can't block boot:
//<NAS_HOSTNAME>/shared /mnt/shared cifs credentials=/etc/samba/credentials,uid=<PUID>,gid=<PGID>,iocharset=utf8,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=600,x-systemd.mount-timeout=30 0 0
Reload systemd & test
You should see something like:
With x-systemd.automount the share mounts on first access instead: ls /mnt/shared, then findmnt /mnt/shared.
Repeat this for any other machines you need to mount the share to. For a desktop (file manager, KDE Dolphin), see Mounting NAS shares on a desktop.
Complete instruction for client¶
sudo apt install cifs-utils -y
sudo mkdir -p /mnt/shared
sudo nano /etc/samba/credentials # username= / password=
sudo chmod 600 /etc/samba/credentials
sudo nano /etc/fstab
fstab entry:
//<NAS_HOSTNAME>/shared /mnt/shared cifs credentials=/etc/samba/credentials,uid=<PUID>,gid=<PGID>,iocharset=utf8,_netdev 0 0
Then: