Computers & Electronics
105,443 views
25 min · 3 min read
7 steps
Advanced

How to build a simple networked file server with Samba for cross‑platform file sharing

This guide walks you through building a simple networked file server using Samba so Windows, macOS, and Linux machines can share files. You’ll set up a small Linux host, create a shared folder, configure Samba permissions, and test access from clients. Expect to spend about 30–90 minutes depending on familiarity with the command line.

Verified by pleasexplain editors
  1. Step 1: Prepare the server machine

    Install a minimal Linux distribution or use an existing Ubuntu/Debian machine with at least 2 GB RAM and 10 GB free disk. Update packages with sudo apt update && sudo apt upgrade -y and reboot if the kernel updated; keeping the OS current reduces compatibility and security issues.

    [Illustration: a simple desktop terminal showing package update commands on a Linux screen]

  2. Step 2: Install Samba packages

    Install Samba and necessary utilities with sudo apt install samba smbclient -y (or the equivalent yum/dnf command). Confirm the samba version with smbd --version; having a recent stable release (within 1–2 years) ensures SMB3 support for faster and more secure transfers.

    [Illustration: terminal window installing samba packages and a package list on screen]

  3. Step 3: Create a shared directory

    Make a dedicated folder such as /srv/samba/share with sudo mkdir -p /srv/samba/share and set ownership to a service user or group: sudo chown nobody:users /srv/samba/share and sudo chmod 2770 /srv/samba/share. Using a fixed path and group permissions simplifies access control and avoids accidental exposure of system files.

    [Illustration: file manager view showing /srv/samba/share folder and terminal creating it]

  4. Step 4: Add Samba users and set passwords

    Create or reuse Linux users for access: sudo useradd -M -s /sbin/nologin alice and then add Samba credentials with sudo smbpasswd -a alice (enter a strong password). Samba requires its own password store; mapping to constrained system accounts limits shell access and improves safety.

    [Illustration: terminal prompting for smbpasswd password entry for a user named alice]

  5. Step 5: Edit smb.conf to define a share

    Open /etc/samba/smb.conf and add a share block like [shared] path = /srv/samba/share valid users = @smbshare users browseable = yes read only = no create mask = 0660 directory mask = 2770. Keep the global section standard and only add the minimal share to reduce misconfiguration risks.

    [Illustration: text editor showing smb.conf with a new [shared] section highlighted]

  6. Step 6: Restart Samba and open firewall ports

    Apply changes with sudo systemctl restart smbd nmbd and enable services: sudo systemctl enable smbd. If using UFW, allow Samba with sudo ufw allow 137/udp, sudo ufw allow 138/udp, sudo ufw allow 139/tcp, sudo ufw allow 445/tcp or sudo ufw allow Samba. Ensuring the firewall allows SMB ports lets clients discover and connect while keeping other ports closed.

    [Illustration: terminal restarting samba services and ufw rules being added]

  7. Step 7: Test from client machines

    From a Windows client, connect to \server-ip amedshare using File Explorer and the Samba username/password. From macOS use Finder -> Go -> Connect to Server with smb://server-ip/namedshare and from Linux try smbclient //server-ip/namedshare -U alice or mount with sudo mount -t cifs. Test reading, writing, and permission behavior for 5–10 minutes to confirm expected access and adjust masks if needed.

    [Illustration: split-screen showing Windows Explorer, macOS Finder, and a Linux terminal connecting to the same network share]


  • Use a static IP or DHCP reservation for the server so clients always reach the same address.
  • Back up the /etc/samba/smb.conf file before editing; restoreable copies save troubleshooting time (cp /etc/samba/smb.conf /etc/samba/smb.conf.bak).
  • Limit allowed users with valid users or hosts allow/deny to reduce exposure; prefer group-based control for multiple accounts.
  • For better performance on high-latency networks, enable SMB2/SMB3 in smb.conf and test transfer speeds with a 100 MB file.
  • Consider storing the share on a dedicated partition or separate disk to avoid filling the system volume; monitor free space with df -h daily at first.
  • Use strong passwords and consider integrating with LDAP or Active Directory for larger environments to centralize authentication.

  • Do not expose SMB ports directly to the public internet; SMB was not designed for wide-area untrusted exposure and invites attacks.
  • Avoid using chmod 0777 on shared folders; overly permissive modes can let any local account modify or delete files accidentally.
  • If you change samba passwords, remember to update saved credentials on client machines or they will fail to reconnect until re-entered.
  • Editing smb.conf with syntax errors can break sharing; always test with testparm before restarting services to catch mistakes.

Was this guide helpful?