21.1. Choosing a File Sharing Protocol

A file sharing decision has three moving parts that must agree: the protocol, the identity model, and the network that carries it. This section fixes the vocabulary for all three so the server sections can concentrate on configuration.

21.1.1. NFS for Unix Systems and SMB for Mixed Clients

NFS and SMB solve the same problem with different histories. NFS was designed for Unix-to-Unix sharing and still does that job with the least friction on an all-Linux network: a mount looks like a local filesystem, permissions are the familiar owner/group/other bits, and the kernel client handles locking, caching, and recovery. SMB was designed around authenticated user accounts and Windows clients, and modern Samba makes it equally at home on Linux: it carries per-user passwords, negotiates its own signing and encryption, and understands Windows conventions such as hidden and archive attributes that NFS does not represent.

Criterion NFS (v4.2) SMB (Samba, SMB2/SMB3)
Natural clients Linux and Unix systems with kernel mounts Windows, macOS, desktop Linux, and Linux CLI clients
Identity on the wire Numeric UID/GID (sec=sys) or Kerberos principals Authenticated user name and password (or domain ticket)
Server-side account requirement None for sec=sys; matching UIDs suffice An SMB account per user (smbpasswd/pdbedit), separate from login passwords
Transport security None built into sec=sys; Kerberos (krb5i/krb5p) or an encrypted tunnel Signing mandatory and encryption negotiable inside the protocol
Typical port surface One TCP port (2049) for NFSv4 One TCP port (445)
Permission model Unix modes and POSIX ACLs; NFSv4 ACLs mapped on top Unix modes and POSIX ACLs underneath, Windows-style ACLs optional
Locking Stateful locks and leases inside the protocol Oplocks/leases and byte-range locks inside the protocol
Best fit Homogeneous Linux server-to-server and workstation shares Mixed-client offices, user home shares, anything Windows touches

Both protocols serve the same directories here: /srv/nfs/team is exported by NFS as /team and published by Samba as the share team, so the choice of protocol never forks the data into two copies. That is the normal arrangement - pick the storage layout once, then decide per client population which protocol exposes it.

Other mechanisms exist but serve different shapes of problem: plain scp/rsync over SSH (Chapter 20) moves files between machines without continuous sharing; HTTP and WebDAV fit publish-once-read-many distributions; iSCSI, CephFS, and clustered filesystems (Chapter 33) export block or object storage rather than a file tree. When the requirement is "several machines work on the same files as if local", NFS and SMB are the two answers worth configuring.

21.1.2. Identity Mapping, Permissions, and Trust Boundaries

Every file operation arrives at the server carrying some claim about who is acting, and the server turns that claim into Unix credentials before checking permissions. The two protocols make that claim differently, and the difference is the single most important thing to understand before exporting anything.

With NFS under sec=sys - the AUTH_SYS flavor that a plain Debian server uses by default - the client kernel sends the numeric UID and GID of the process performing each operation. Nothing authenticates those numbers. If john has UID 2100 on the client, the server sees "UID 2100" and enforces /srv/nfs/team's permissions against that number; whether the server's own account database calls 2100 "john" is irrelevant to enforcement. This works beautifully when every host assigns the same numbers to the same people, and it fails silently when they do not: a file created by an unknown UID simply shows up owned by that number, with no account behind it. Section 21.3.3 demonstrates both sides of this on the lab.

How identity crosses the wire in NFS and SMB

Figure 21.2. In both protocols the server ends up applying Unix permissions to a server-side credential. NFS with sec=sys lets the client assert numeric IDs directly, so the numbers must agree by policy. SMB authenticates a user name, and the server maps that account to its own Unix identity before any permission check.

SMB inverts the trust: the client proves knowledge of a password for a named account, the server checks its own password database (tdbsam here, or a domain backend), and only then maps the authenticated user to a Unix account. The numbers never cross the wire, so UID alignment between hosts is not required for SMB to work - the server's mapping decides everything. That is also why an SMB account is a separate object from the login account: smbpasswd -a john creates a SMB credential for the existing Unix user, with its own password.

NFS compensates for its trusting identity model with root_squash, which rewrites a client root's UID 0 to the anonymous identity 65534 (nobody) before permissions are checked, and with export lists that name exactly which hosts or networks may mount at all. Those are coarse but effective controls: they bound what a compromised client can claim, though they cannot tell two human users on the same client apart. For per-user authentication over NFS, the protocol's own answer is Kerberos (sec=krb5 and its integrity- and privacy-protecting variants), which needs a KDC and keytabs - Chapter 35 builds that infrastructure.

The trust boundary, then, has layers, and this chapter configures each one where it belongs:

  • The network layer (nftables on the server and the router) decides which source addresses can reach ports 2049 and 445 at all.
  • The service layer - NFS export lists, Samba hosts allow and share valid users - decides which of those addresses and accounts may use which directories.
  • The filesystem layer - Unix modes, POSIX ACLs, and quotas - decides what any accepted identity can actually do to the files.

A request must pass all three. When access fails, checking the layers in that order finds the refusing one quickly, and Section 21.7.3 demonstrates each layer refusing the same client in turn.

21.1.3. Selecting Storage and Planning Network Access

File service data deserves its own filesystem. A dedicated volume keeps user growth from filling the root filesystem, makes quotas meaningful (quotas are per-filesystem), makes the backup story simple (one mount to back up), and lets the share tree be moved or grown without reinstalling anything. Chapter 11 and Chapter 12 cover the mechanics; this chapter uses a 2 GiB ext4 volume on /dev/vdb mounted at /srv/nfs, created with ext4's built-in quota feature and ACL support, because ext4 carries both natively and is the safe default the earlier chapters established. The same layout works on XFS if your workload favors it - quotas and POSIX ACLs exist there too, with different repair and shrink properties.

Under that mount point, the tree follows the access policy rather than the reverse:

Directory Owner:group Mode Purpose
/srv/nfs/team john:team 2770 group collaboration; both readers are members of team
/srv/nfs/private john:john 0700 one user's private files
/srv/nfs/public root:team 0755 read-only distribution
/srv/nfs/scratch john:team 0777 disposable world-writable area for demonstrations
/srv/nfs/admin root:root 0700 NFSv3 comparison export with no_root_squash

The set-group-ID bit on team (mode 2770) makes new files inherit the team group so members can share them - the same mechanism Chapter 5 used for local collaboration, now visible through two network protocols.

Network planning is decided before the first export line is written, because export lists and firewall rules both key on addresses. The server LAN 192.168.230.0/24 is trusted for direct service: client1 lives there. The remote LAN 192.168.231.0/24 is not trusted for direct service: its traffic is routed to the server, but the server refuses it at the firewall, and remoteclient instead uses a WireGuard tunnel on 10.21.0.0/24, which the export lists and Samba policy admit explicitly. Each access path also gets a DNS name - files.lab.example for the LAN, files-vpn.lab.example for the tunnel endpoint - so configurations reference a stable name rather than an address that might move. Chapter 22 replaces the lab's one-line dnsmasq with a real DNS architecture when the site grows past a handful of records; Chapter 17 covers the resolver configuration the clients need meanwhile.