
Sharing files across multiple systems in a network can make collaboration and resource access seamless. Two popular methods for network file sharing in Linux are NFS (Network File System) and Samba. While NFS is typically used in Unix/Linux environments, Samba is widely used for interoperability between Linux and Windows systems.
1. Sharing Files with NFS
Step 1: Install NFS
sudo apt update && sudo apt install nfs-kernel-server
Step 2: Create a Shared Directory
sudo mkdir -p /mnt/shared
sudo chown nobody:nogroup /mnt/shared
sudo chmod 777 /mnt/shared
Step 3: Configure Exports
Edit the NFS exports file:
sudo nano /etc/exports
Add:
/mnt/shared 192.168.1.0/24(rw,sync,no_subtree_check)
Then:
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
Step 4: Mount the Share on Client
sudo apt install nfs-common
sudo mount server-ip:/mnt/shared /mnt
2. Sharing Files with Samba
Step 1: Install Samba
sudo apt update && sudo apt install samba
Step 2: Create a Shared Directory
sudo mkdir -p /mnt/shared
sudo chmod 777 /mnt/shared
Step 3: Configure Samba
Edit the Samba config file:
sudo nano /etc/samba/smb.conf
Add:
[SharedFolder]
path = /mnt/shared
browseable = yes
read only = no
guest ok = yes
Step 4: Restart Samba
sudo systemctl restart smbd
Step 5: Access from Windows
Open Run (Win + R
) and type:
\\server-ip\SharedFolder
Choosing Between NFS and Samba
- NFS is ideal for Linux-to-Linux environments due to simplicity and speed.
- Samba is the better choice for cross-platform sharing between Linux, Windows, and macOS.
How to Share Files Over the Network Using NFS or Samba (F.A.Q)
Which is faster, NFS or Samba?
NFS generally offers better performance in Linux-only environments, while Samba is slightly slower but more compatible with Windows.
Can I password-protect my Samba share?
Yes, you can create Samba users with sudo smbpasswd -a username
for secured access.
Does NFS work on Windows?
Yes, Windows supports NFS, but it may require enabling it through “Turn Windows features on or off.”
Can I use both NFS and Samba on the same machine?
Absolutely, you can configure both services for different use cases.