Share Folders on Linux Network: Easy Steps
In this article
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 addrorhostname -I). - For Samba: the
sambapackage installed. For NFS:nfs-kernel-server(Debian/Ubuntu) ornfs-utils(Fedora/RHEL).
Step-by-Step: Sharing with Samba (Windows/Linux/macOS)
- 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). - 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, use777or better, create a group. - Edit the Samba config file – Open
/etc/samba/smb.confwith a text editor (e.g.,sudo nano /etc/samba/smb.conf). At the bottom, add: - Set a Samba password – Run
sudo smbpasswd -a yourusernameand enter a password. This is separate from your Linux login password. - Restart Samba –
sudo systemctl restart smbd(andnmbdif it exists). - Open firewall ports – If you use UFW:
sudo ufw allow samba. If using firewalld:sudo firewall-cmd --permanent --add-service=sambathensudo firewall-cmd --reload. - Test from another machine – On Windows, open File Explorer and type
\\IP-of-Linux\MyShare. On Linux, usesmbclient //IP/MyShare -U yourusernameor mount withmount -t cifs //IP/MyShare /mnt -o username=yourusername.
[MyShare] path = /srv/share available = yes valid users = yourusername read browsable = yes public = yesReplace
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).
Step-by-Step: Sharing with NFS (Linux-to-Linux)
- Install NFS server – Debian/Ubuntu:
sudo apt install nfs-kernel-server. Fedora:sudo dnf install nfs-utils. - Create and set permissions –
sudo mkdir -p /srv/nfsshareandsudo chown nobody:nogroup /srv/nfsshare(or use your user). - Edit exports file – Open
/etc/exportswith nano. Add a line like: - Apply the exports – Run
sudo exportfs -a. - Start NFS service –
sudo systemctl restart nfs-kernel-server(ornfs-serveron Fedora). - Open firewall – UFW:
sudo ufw allow from 192.168.1.0/24 to any port nfs. Firewalld:sudo firewall-cmd --permanent --add-service=nfsand reload. - Test from client – On the client Linux:
sudo mount -t nfs IP-of-server:/srv/nfsshare /mnt. Check withdf -h /mnt.
/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).
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/exportsand not runningexportfs -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 = yesin 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/fstablike//server/share /mnt/share cifs credentials=/etc/samba/creds,uid=1000,gid=1000,iocharset=utf8 0 0for Samba, orserver:/path /mnt nfs defaults 0 0for NFS. - If you only need occasional access, use
sshfs(installsshfs) for a simple, secure share over SSH.
Troubleshooting
If you can't see the share, try these in order:
- Check the service is running –
sudo systemctl status smbdornfs-kernel-server. If not, start it. - Test from the server itself –
smbclient -L localhost -U yourusernamefor Samba;showmount -e localhostfor NFS. If that fails, the config is wrong. - Check firewall – Temporarily disable UFW (
sudo ufw disable) to test. If it works, re-enable and add the proper rules. - Check network connectivity – Ping the server from the client. If no reply, you're on different subnets or the server is down.
- Look at logs – For Samba:
sudo tail -f /var/log/samba/log.smbd. For NFS:sudo journalctl -u nfs-kernel-server. - 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.