Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Linux

NFS vs SMB: which file-sharing protocol fits your setup

NFS vs SMB for Linux, Windows and macOS: how each handles users, permissions, locking and encryption, with working setups and the security rules both need.

CloudSat teamNovember 18, 20266 min read
Two streams of glowing folders crossing between distant machines along separate paths of light
On this pageThe short answer

NFS and SMB both let many machines work with files stored on one server, and both are decades old and still evolving. They come from different worlds: NFS grew up on Unix, where machines trust each other's user IDs, and SMB on Windows, where every session authenticates a user. That difference in identity explains most of the practical differences, and it is the first thing to look at when you choose.

The short answer

  • Linux servers sharing files with other Linux servers: NFS. It is built into the kernel, has little overhead and maps directly onto Unix permissions.
  • Windows or macOS desktops, or a mix of everything: SMB through Samba. Every desktop OS has a client built in, and users log in with a name and password.
  • Hypervisor and container storage: usually NFS, which most virtualization platforms accept as shared storage.
  • Anything across the internet: neither protocol directly. Put the share inside a VPN, or use SFTP or a sync tool instead.

How they differ

Aspect NFS (version 4.2) SMB (version 3.1.1)
Native clients Linux, BSD, macOS; Windows has an optional NFSv3 client Windows, macOS, Linux, Android and iOS apps
Network port TCP 2049 for NFSv4 (NFSv3 also needs rpcbind and helper ports) TCP 445
Who is the user? By default, the client states a numeric UID and GID and the server believes it The user authenticates per session with a password or Kerberos
Permissions Unix modes and, optionally, NFSv4 ACLs Windows-style ACLs; Samba maps them onto Unix permissions
Encryption Kerberos krb5p, or TLS on recent Linux systems Built into SMB 3, enforceable per share or per server
Locking Integrated into NFSv4 with leases Opportunistic locks and leases, tuned for desktop apps
Browsing You mount a known path Shares show up in file managers

Run NFSv4 rather than NFSv3 on any new setup: one port, integrated locking and stronger security options. On the SMB side, SMB1 should be off everywhere. Current Windows versions and Samba releases already disable it by default.

Identity is the real difference

With NFS's default security flavor, sec=sys, the server trusts whatever user ID the client sends. If two machines map user 1000 to different people, they see each other's files. If an untrusted machine can reach the export, it can claim any UID it likes. The only built-in guard is root_squash, on by default, which maps a client's root user to an unprivileged ID.

So plain NFS is safe only between machines you administer, with consistent user IDs, on a network you control. For anything less trusted, use Kerberos (sec=krb5p authenticates and encrypts) or pick SMB.

SMB asks every connection to prove who it is, which suits shared office storage: Alice and Bob log in as themselves from any device, and the server applies their permissions. The price is user management on the server, through Samba's own password database or a domain.

Set up an NFS share

On a Debian or Ubuntu server, export a directory to one private subnet:

sudo apt install -y nfs-kernel-server
sudo mkdir -p /srv/share
echo '/srv/share 10.10.0.0/24(rw,sync,no_subtree_check)' | sudo tee -a /etc/exports
sudo exportfs -ra
sudo exportfs -v          # shows what is exported and with which options

sync makes the server commit writes to disk before confirming them. Its opposite, async, is faster and can lose data that clients believe was saved if the server crashes, so keep sync unless you understand the trade.

On each Linux client:

sudo apt install -y nfs-common
sudo mkdir -p /mnt/share
sudo mount -t nfs4 10.10.0.5:/srv/share /mnt/share

To mount at boot, add a line to /etc/fstab. _netdev tells the system to wait for the network first, and nofail lets the client finish booting even when the server is down:

10.10.0.5:/srv/share  /mnt/share  nfs4  defaults,_netdev,nofail,noatime  0  0

NFS mounts are hard by default: when the server disappears, programs that touch the mount wait until it returns, and a stuck ls is the visible symptom. That behavior protects your data. A soft mount returns errors to applications in the middle of a write instead, which can leave files half-written, so keep hard for anything you care about and fix the server or the network rather than the mount option.

Set up an SMB share with Samba

Install Samba, then describe the share in /etc/samba/smb.conf:

sudo apt install -y samba
sudo groupadd -f team
sudo mkdir -p /srv/smb/team
sudo chgrp team /srv/smb/team && sudo chmod 2770 /srv/smb/team
[global]
   server min protocol = SMB3
   server smb encrypt = required

[team]
   path = /srv/smb/team
   read only = no
   valid users = @team
   create mask = 0660
   directory mask = 2770

The two global lines refuse old protocol versions and unencrypted sessions. Then give each person a Unix account in the group and a Samba password, which is separate from their login password:

sudo useradd -M -s /usr/sbin/nologin -G team alice
sudo smbpasswd -a alice
testparm -s                 # checks smb.conf for mistakes
sudo systemctl restart smbd

Clients connect with their usual tools: Map network drive or net use Z: \\10.10.0.5\team /user:alice on Windows, Connect to Server with smb://10.10.0.5/team on macOS, and cifs-utils on Linux:

sudo mount -t cifs //10.10.0.5/team /mnt/team -o credentials=/root/.smb-team,uid=1000,gid=1000

The credentials file holds username= and password= lines; make it readable by root only.

Security rules for both

  • Never expose 2049 or 445 to the internet. Both protocols attract constant scanning, and many internet providers block port 445 anyway. Allow them only from the subnet or VPN that needs them.
  • Use a VPN between sites and servers. WireGuard adds little overhead and turns any file share into a private one. A file server on a CloudSat storage VPS should keep both ports closed in its cloud firewall and serve clients through such a tunnel.
  • Encrypt where the network is not yours: krb5p for NFS, server smb encrypt = required for Samba.
  • Back up the share itself. A share replicates mistakes instantly: a deleted folder is gone for every client. Snapshots or versioned backups of the exported directory are the safety net.

What should not live on a network share

Some software assumes local disk semantics and corrupts data on a network file system. SQLite databases, the data directories of Prometheus and Uptime Kuma, and database engines in general belong on local storage; Prometheus and Uptime Kuma both document that NFS is not supported. Replicate those at the application level and share only plain files, media, build artifacts and home directories.

FAQ

Which one is faster?

It depends on the workload, the client and the tuning, so measure with your own files rather than trusting a general answer. Between Linux machines, NFS usually has less overhead. Windows clients get features such as SMB Multichannel that NFS cannot offer them. Test with fio, or by timing a representative copy.

Can I share the same folder over NFS and SMB at once?

Yes, and Samba and the NFS server can export the same directory. Avoid having clients of both protocols edit the same files at the same time, because their locking does not fully coordinate.

What is SMB over QUIC?

A Windows feature that carries SMB inside TLS 1.3 over UDP port 443, so remote users can reach file servers without a VPN. Windows Server 2025 offers it in its Standard and Datacenter editions. Support outside Windows is still limited, so treat it mainly as a Windows option, and keep port 445 closed either way.

How do I share files with people outside my network?

Use something designed for it: SFTP for technical users, or a sync and share application such as Nextcloud or Syncthing for everyone else. Network file protocols assume a trusted LAN.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.