Step-by-Step Guide to Setup NFS and Samba on Linux (Beginner Friendly)

 

📌 Introduction:

Sharing files across a network is a common task in Linux system administration. Two popular methods are NFS (Network File System) and Samba (SMB/CIFS).
In this guide, you’ll learn how to set up both NFS and Samba step-by-step, so you can enable file sharing between Linux and Windows systems.


🔧 Part 1: Setting Up NFS (Linux-to-Linux File Sharing)

✅ 1. Install NFS Packages

On both server and client:

bash
sudo yum install nfs-utils -y # RHEL/CentOS sudo apt install nfs-kernel-server nfs-common -y # Ubuntu/Debian

✅ 2. Create Shared Directory on NFS Server

bash
sudo mkdir -p /srv/nfs_share sudo chown nobody:nogroup /srv/nfs_share sudo chmod 777 /srv/nfs_share

✅ 3. Configure NFS Exports

Edit the exports file:

bash
sudo nano /etc/exports

Add:

bash
/srv/nfs_share 192.168.1.0/24(rw,sync,no_subtree_check)

Then apply the export:

bash
sudo exportfs -a

✅ 4. Start and Enable NFS Services

bash
sudo systemctl enable --now nfs-server

✅ 5. Allow Firewall (RHEL-based systems)

bash
sudo firewall-cmd --permanent --add-service=nfs sudo firewall-cmd --reload

✅ 6. Mount from NFS Client

On client machine:

bash
sudo mount 192.168.1.10:/srv/nfs_share /mnt

Make it permanent:

bash
echo "192.168.1.10:/srv/nfs_share /mnt nfs defaults 0 0" | sudo tee -a /etc/fstab

💡 NFS Use Cases

  • Best for Linux-to-Linux file sharing

  • Lightweight and fast for internal networks


🧰 Part 2: Setting Up Samba (Linux-to-Windows File Sharing)

✅ 1. Install Samba

bash
sudo yum install samba -y # RHEL/CentOS sudo apt install samba -y # Ubuntu/Debian

✅ 2. Create Shared Folder

bash
sudo mkdir -p /srv/samba_share sudo chown nobody:nogroup /srv/samba_share sudo chmod 777 /srv/samba_share

✅ 3. Edit Samba Configuration

Open:

bash
sudo nano /etc/samba/smb.conf

Add at the end:

bash
[sambashare] path = /srv/samba_share browsable = yes read only = no guest ok = yes

✅ 4. Restart Samba Service

bash
sudo systemctl restart smb sudo systemctl enable smb

✅ 5. Access From Windows

  • Open File Explorer

  • Type in address bar:
    \\192.168.1.10\sambashare

✅ Now you can copy/paste files between Linux and Windows!


🔒 Optional: Secure Samba with a Username

bash
sudo smbpasswd -a yourusername

Update smb.conf to require login:

java
guest ok = no valid users = yourusername

📦 Useful Accessories [Amazon Affiliate Links]

🔗 You can add these to your blog post to earn commissions:


📌 Conclusion

Both NFS and Samba are powerful file-sharing protocols.

  • Use NFS when working Linux-to-Linux

  • Use Samba for Linux-to-Windows or cross-platform sharing

Experiment with both to understand how Linux file sharing works in real time.
Have questions or want to see video tutorials? Let me know in the comments!


Disclosure: Some links in this post are affiliate links. If you purchase through them, I may earn a small commission at no extra cost to you.

Comments

Popular posts from this blog

How to Configure Samba and Work with SUSE Linux – Step-by-Step Guide for Sysadmins

Top 5 Linux Books Every Beginner Should Read in 2025