How to Set Up an NFS Share on Linux (Fast File Sharing Between Linux Machines)

Samba (tutorial 31) is for Windows and Macs. Between Linux machines — a second server, a Raspberry Pi, a Proxmox box, a Docker host that needs the media library — NFS is simpler and faster: the shared folder mounts as if it were a local disk, with no passwords and almost no overhead.
Quick reference
| Task | Command |
|---|---|
| Install (server) | sudo apt install nfs-kernel-server -y |
| Share a folder | one line in /etc/exports |
| Apply | sudo exportfs -ra |
| Install (client) | sudo apt install nfs-common -y |
| Mount | sudo mount 192.168.1.50:/srv/nfs/media /mnt/media |
| Permanent | fstab line with nfs and nofail |
1. On the server
sudo apt install nfs-kernel-server -y
sudo mkdir -p /srv/nfs/media
If the data is already somewhere else (say /mnt/data/media), export that path directly — no need to move it.
sudo nano /etc/exports
/mnt/data/media 192.168.1.0/24(rw,sync,no_subtree_check)
That shares the folder with every machine on your network, read-write. For one machine only, use its IP instead of the range. For read-only, ro instead of rw.
sudo exportfs -ra
sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo exportfs -v
The last command lists what's shared.
2. On the client
sudo apt install nfs-common -y
sudo mkdir -p /mnt/media
sudo mount 192.168.1.50:/mnt/data/media /mnt/media
ls /mnt/media
3. Make it permanent
sudo nano /etc/fstab
192.168.1.50:/mnt/data/media /mnt/media nfs defaults,nofail,_netdev 0 0
_netdev tells the system to wait for the network before mounting; nofail stops the boot hanging if the server is off. Test with sudo umount /mnt/media && sudo mount -a.
4. Permissions: the bit everyone trips over
NFS passes numeric user IDs, not names. If your user is UID 1000 on both machines, everything just works. If not, files look owned by a stranger and writes fail. Three fixes, pick one:
- Make the UIDs match (id on both; sudo usermod -u 1000 name on the odd one).
- Map everyone to one user on the server: add all_squash,anonuid=1000,anongid=1000 to the exports line.
- For a read-only media share, it doesn't matter — just use ro.
Docker on another host
Mount the NFS share on the Docker host as above, then use the mount path as a normal volume (/mnt/media:/media:ro). Or let Docker mount it directly:
volumes:
media:
driver_opts:
type: nfs
o: addr=192.168.1.50,ro,nfsvers=4
device: ":/mnt/data/media"
NFS or Samba?
Both can share the same folder. Linux clients and Docker: NFS. Windows, Macs and phones: Samba. A media library typically has both.
Troubleshooting
"mount.nfs: access denied by server". The client's IP isn't in the exports line, or you forgot exportfs -ra.
"Connection timed out". Firewall on the server, or NFS isn't running: sudo systemctl status nfs-server.
Client hangs when the server goes away. Add soft,timeo=30 to the mount options so operations fail instead of waiting forever.
Slow. Make sure both sides use NFSv4 (nfsstat -m shows the version) and that the network is gigabit. NFS over Wi-Fi is painful.
Wrapping up
One line in /etc/exports, exportfs -ra, mount on the client, fstab with nofail. Match the UIDs or squash them, and a folder on the server behaves like a local disk on every Linux box in the house.
