Not fully verified: Samba/NFS install and config commands are checked against official docs and have not been run in WSL; basic file permission operations were verified in WSL.
Samba and NFS are the two most mature sharing options on Linux: Samba interoperates with Windows/macOS, NFS targets Linux-to-Linux high-performance scenarios. This article gives deployment steps in order, plus rollback and troubleshooting.
1. TL;DR: pick by scenario
| Scenario | Recommended | Reason |
|---|---|---|
| Linux ↔ Windows | Samba | Native SMB/CIFS; Windows clients mount directly |
| Linux ↔ Linux high performance | NFS | POSIX semantics, low overhead, good for many small files |
| Temporary single-machine share | Python http.server | No config; one command; temporary only |
- Prefer system services (Samba/NFS) in production; use a single-file server only for temporary debugging.
- Do not expose temporary shares to the public internet; add
--bind 127.0.0.1.
2. Samba (SMB) file sharing
Samba implements SMB/CIFS, exposing Linux directories to Windows/macOS/Linux clients [1]. Ubuntu’s official docs also start from the samba package [3].
sudo apt update && sudo apt install -y samba
sudo mkdir -p /srv/samba/share
sudo chown root:users /srv/samba/share
sudo chmod 2775 /srv/samba/share
Append a share section at the end of /etc/samba/smb.conf:
[shared]
path = /srv/samba/share
browseable = yes
read only = no
guest ok = yes
Validate config and start the service:
sudo testparm -s
sudo systemctl enable --now smbd
testparm -s parses smb.conf and reports syntax errors; run it before starting [2].
Client mounts
- Windows:
\SERVER_IPshared - Linux:
sudo mount -t cifs //SERVER_IP/shared /mnt -o guest
3. NFS file sharing
NFS is Linux’s native network file system; once mounted, it behaves like a local disk [4].
sudo apt update && sudo apt install -y nfs-kernel-server
sudo mkdir -p /srv/nfs/share
sudo chown nobody:nogroup /srv/nfs/share
Add an export rule to /etc/exports:
/srv/nfs/share 192.168.1.0/24(rw,sync,no_subtree_check)
Apply and mount:
sudo exportfs -ra
Client:
sudo mount -t nfs SERVER_IP:/srv/nfs/share /mnt
mount.nfs is mount(8)’s NFS-specific subcommand, supporting NFSv3/v4 [5]. exportfs maintains the NFS export table; -ra re-reads /etc/exports and applies it [6].
4. Rollback and troubleshooting quick reference
Rollback
- Samba:
sudo systemctl stop smbd && sudo rm /etc/samba/smb.conf.bak(back up config first) - NFS:
sudo exportfs -u CLIENT_IP:/srv/nfs/shareto unexport a single entry, orsudo systemctl stop nfs-server
| Symptom | Cause | Fix |
|---|---|---|
| testparm reports unknown parameter | smb.conf typo or unsupported by version | Check Samba version; comment out suspect lines |
| mount error: Permission denied | export not applied or IP range mismatch | sudo exportfs -v to inspect current exports |
| Windows can’t reach \IPshare | smbd not running or firewall | sudo systemctl status smbd; allow 139/445 |
| ls hangs after mount | NFS server down or network drop | umount -f /mnt first, then investigate network |
5. Limitations
- In WSL2,
apt install sambaandapt install nfs-kernel-servertime out; Samba/NFS server commands were not run in this WSL session; basic file permission operations were verified. - When WSL2 acts as an NFS client, ensure Windows Firewall allows port 2049.
- Containers usually shouldn’t run an NFS server; prefer a dedicated storage node or managed file service.
- Public-internet sharing must use encryption or VPN; WAN transport security is out of scope here.
6. FAQ
Q1: Can Samba and NFS be installed together? Yes. They listen on different ports (Samba 139/445, NFS 2049); coexist as long as firewall rules don’t conflict.
Q2: What does no_root_squash mean in /etc/exports? By default NFS maps root requests to the anonymous user nobody; with no_root_squash, client root keeps root privileges on the server, a security risk — use only on trusted LANs [4].
Q3: Must I restart the service after editing smb.conf? smbd supports hot reload: sudo systemctl reload smbd, safer than restart and won’t drop existing connections.
Q4: Client mount says “Connection refused” — what now? Confirm nfs-server is running, check /etc/exports syntax and the client IP range, then verify exports with showmount -e SERVER_IP.
Q5: Can Windows 10/11 mount NFS? Yes, after installing the “Client for NFS” feature, but only NFSv3 is supported. Samba is recommended for cross-platform use.
References
- [1] smbd(8) – Linux manual page (man7.org) (man7-smbd)
- [2] smb.conf(5) — samba-common-bin — Debian bookworm-backports (debian-smbconf)
- [3] Set up Samba as a file server — Ubuntu Server Docs (ubuntu-samba)
- [4] nfs(5) – Linux manual page (man7.org) (man7-nfs)
- [5] mount.nfs(8) – Linux manual page (man7.org) (man7-mountnfs)
- [6] exportfs(8) – Linux manual page (man7.org) (man7-exportfs)
Major commands in this article were tested on WSL Ubuntu (24.04) and checked against Debian-family and general distro documentation.