Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Share Folders on Linux Network: Easy Steps

· 5 min read · Home Networking

In this article
  1. What You'll Need
  2. Step-by-Step: Sharing with Samba (Windows/Linux/macOS)
  3. Step-by-Step: Sharing with NFS (Linux-to-Linux)
  4. Common Mistakes
  5. Tips
  6. Troubleshooting
  7. Frequently Asked Questions

Yes, sharing folders on a Linux network is easier than you think. You can use Samba (for Windows compatibility) or NFS (for Linux-to-Linux sharing). This guide covers both methods, focusing on Samba for mixed networks and NFS for pure Linux setups. You'll need root or sudo access, and the IP addresses of the computers involved.

What You'll Need

  • A Linux machine with sudo privileges (the one sharing the folder).
  • Another computer on the same network (Linux, Windows, or macOS) to test the share.
  • IP addresses of both machines (find with ip addr or hostname -I).
  • For Samba: the samba package installed. For NFS: nfs-kernel-server (Debian/Ubuntu) or nfs-utils (Fedora/RHEL).

Step-by-Step: Sharing with Samba (Windows/Linux/macOS)

  1. Install Samba – On Debian/Ubuntu: sudo apt install samba. On Fedora: sudo dnf install samba. Confirm it's running: sudo systemctl status smbd (if not, sudo systemctl start smbd).
  2. Create a share directory – For example: sudo mkdir -p /srv/share. Set permissions: sudo chmod 755 /srv/share. If you want write access for everyone, use 777 or better, create a group.
  3. Edit the Samba config file – Open /etc/samba/smb.conf with a text editor (e.g., sudo nano /etc/samba/smb.conf). At the bottom, add:
  4. [MyShare]
       path = /srv/share
       available = yes
       valid users = yourusername
       read
       browsable = yes
       public = yes
    Replace yourusername with your Linux username. If you want guest access, set public = yes and guest ok = yes (but then anyone on the network can read/write).
  5. Set a Samba password – Run sudo smbpasswd -a yourusername and enter a password. This is separate from your Linux login password.
  6. Restart Samba – sudo systemctl restart smbd (and nmbd if it exists).
  7. Open firewall ports – If you use UFW: sudo ufw allow samba. If using firewalld: sudo firewall-cmd --permanent --add-service=samba then sudo firewall-cmd --reload.
  8. Test from another machine – On Windows, open File Explorer and type \\IP-of-Linux\MyShare. On Linux, use smbclient //IP/MyShare -U yourusername or mount with mount -t cifs //IP/MyShare /mnt -o username=yourusername.

Step-by-Step: Sharing with NFS (Linux-to-Linux)

  1. Install NFS server – Debian/Ubuntu: sudo apt install nfs-kernel-server. Fedora: sudo dnf install nfs-utils.
  2. Create and set permissions – sudo mkdir -p /srv/nfsshare and sudo chown nobody:nogroup /srv/nfsshare (or use your user).
  3. Edit exports file – Open /etc/exports with nano. Add a line like:
  4. /srv/nfsshare 192.168.1.0/24(rw,sync,no_subtree_check)
    Replace the IP range with your network's subnet. For a single machine, use its IP like 192.168.1.50(rw,sync).
  5. Apply the exports – Run sudo exportfs -a.
  6. Start NFS service – sudo systemctl restart nfs-kernel-server (or nfs-server on Fedora).
  7. Open firewall – UFW: sudo ufw allow from 192.168.1.0/24 to any port nfs. Firewalld: sudo firewall-cmd --permanent --add-service=nfs and reload.
  8. Test from client – On the client Linux: sudo mount -t nfs IP-of-server:/srv/nfsshare /mnt. Check with df -h /mnt.

Common Mistakes

  • Forgetting to set Samba passwords – Samba uses its own password database; you must run smbpasswd -a.
  • Wrong permissions on the folder – If the folder is owned by root and you want others to write, you need to change ownership or set group write permissions.
  • Firewall blocking ports – Samba uses ports 137-139 and 445; NFS uses port 2049. Missing firewall rules is the most common cause of failure.
  • Editing /etc/exports and not running exportfs -a – Changes won't take effect until you do.
  • Using the wrong IP range – Check your subnet with ip addr; don't guess.

Tips

  • For security, avoid public = yes in Samba unless you're on a trusted home network.
  • Use a dedicated group (e.g., sambashare) to manage access cleanly.
  • To make the share persistent on the client, add a line to /etc/fstab like //server/share /mnt/share cifs credentials=/etc/samba/creds,uid=1000,gid=1000,iocharset=utf8 0 0 for Samba, or server:/path /mnt nfs defaults 0 0 for NFS.
  • If you only need occasional access, use sshfs (install sshfs) for a simple, secure share over SSH.

Troubleshooting

If you can't see the share, try these in order:

  1. Check the service is running – sudo systemctl status smbd or nfs-kernel-server. If not, start it.
  2. Test from the server itself – smbclient -L localhost -U yourusername for Samba; showmount -e localhost for NFS. If that fails, the config is wrong.
  3. Check firewall – Temporarily disable UFW (sudo ufw disable) to test. If it works, re-enable and add the proper rules.
  4. Check network connectivity – Ping the server from the client. If no reply, you're on different subnets or the server is down.
  5. Look at logs – For Samba: sudo tail -f /var/log/samba/log.smbd. For NFS: sudo journalctl -u nfs-kernel-server.
  6. Re-check permissions – Ensure the folder has execute permissions for the user/group trying to access it.

Frequently Asked Questions

Can I share a folder with Windows without installing Samba?

No, Samba is the standard way to share with Windows. Windows doesn't natively understand Linux file systems, so Samba translates.

Is NFS faster than Samba?

NFS is generally faster on Linux-to-Linux connections because it's lower overhead, but for mixed networks Samba is more compatible. The difference is negligible for home use.

How do I make a share read-only?

In Samba, set read> in the share definition. In NFS, use ro instead of rw in /etc/exports.

What is the difference between guest access and user access?

Guest access allows anyone on the network to connect without a password. User access requires a valid Samba username and password. Guest is easier but less secure.

Can I share a folder that is on an external hard drive?

Yes, just point the share path to the mount point (e.g., /mnt/external). Ensure the drive is mounted before Samba/NFS starts.

Do I need to restart Samba after every change?

Yes, for changes to smb.conf to take effect, restart with sudo systemctl restart smbd. For NFS exports, sudo exportfs -a is enough.