RECOMMENDED Amnezia Premium: Works Where Other VPNs Fail

Unblockable AmneziaWG 2.0 & XRay protocols. Perfect for lag-free access to ChatGPT, Claude AI, global freelance marketplaces, and restricted streaming networks with clean RAM-only privacy.

Samba File Server on Linux: Set Up Shared Folders for Windows, Linux and macOS (2026)

Samba lets a Linux machine share folders and printers with Windows, macOS and other Linux computers over the SMB protocol, the same protocol Windows uses for network drives. A home NAS, a shared folder in a small office, a place for scans from the printer: all of this is a Samba share. Samba 4 can also act as an Active Directory domain controller, but this guide covers the common case, a file server.

Current versions: Samba 4.25 upstream, 4.22 in Debian 13, 4.17 in Debian 12. The configuration below works on all of them and on Ubuntu, Rocky Linux and AlmaLinux.

Install Samba

Samba file server configuration in a Linux terminal
sudo apt install samba                    # Debian, Ubuntu
sudo dnf install samba samba-client      # Rocky Linux, AlmaLinux, Fedora
sudo systemctl enable --now smb          # on Rocky/Alma/Fedora; on Debian smbd starts automatically

The main configuration file is /etc/samba/smb.conf. Make a copy before editing: sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orig.

Create a shared folder for users

The most useful setup: a folder that several people can read and write, each with their own password. Create a group, a folder and give the group access:

sudo groupadd -f sambashare
sudo mkdir -p /srv/samba/shared
sudo chgrp sambashare /srv/samba/shared
sudo chmod 2770 /srv/samba/shared       # 2 = new files inherit the group

Add the share at the end of /etc/samba/smb.conf:

[shared]
   path = /srv/samba/shared
   browseable = yes
   read only = no
   valid users = @sambashare
   create mask = 0660
   directory mask = 2770

Samba keeps its own passwords, separate from Linux login passwords. Each user needs a Linux account and a Samba password:

sudo useradd -M -s /usr/sbin/nologin alice   # account without home and shell, only for Samba
sudo usermod -aG sambashare alice
sudo smbpasswd -a alice                     # set the Samba password
sudo smbpasswd -e alice                     # enable the account

Check the configuration and restart the service:

testparm
sudo systemctl restart smbd       # Debian, Ubuntu
sudo systemctl restart smb        # Rocky, AlmaLinux, Fedora

A public folder without a password

For a home network, a guest folder is sometimes enough. In the [global] section add map to guest = bad user, then the share:

[public]
   path = /srv/samba/public
   read only = no
   guest ok = yes
   force user = nobody
   create mask = 0666
   directory mask = 0777

Anyone on the network can read and write here, so use it only in a trusted home network and never on a server with a public IP.

Firewall and SELinux

sudo ufw allow from 192.168.1.0/24 to any app Samba     # Ubuntu, Debian with ufw
sudo firewall-cmd --permanent --add-service=samba        # Rocky, AlmaLinux, Fedora
sudo firewall-cmd --reload

On Rocky Linux and AlmaLinux SELinux blocks access to folders that are not labelled for Samba. Set the label once:

sudo semanage fcontext -a -t samba_share_t '/srv/samba(/.*)?'
sudo restorecon -Rv /srv/samba

If clients see the share but get “access denied”, SELinux is the first thing to check: sudo ausearch -m avc -ts recent.

Connect to the share

ClientHow to connect
WindowsIn File Explorer type \\server-ip\shared, or right-click “This PC” → “Map network drive”
macOSFinder → Go → Connect to Server → smb://server-ip/shared
Linux desktopIn the file manager address bar: smb://server-ip/shared
Linux terminalsmbclient //server-ip/shared -U alice or mount with cifs-utils (below)

To mount a share permanently on Linux, install cifs-utils, keep the password in a separate file readable only by root and add a line to fstab:

sudo apt install cifs-utils
printf 'username=alice\npassword=secret\n' | sudo tee /root/.smb-alice >/dev/null
sudo chmod 600 /root/.smb-alice
sudo mkdir -p /mnt/shared
echo '//192.168.1.10/shared /mnt/shared cifs credentials=/root/.smb-alice,uid=1000,gid=1000,_netdev 0 0' | sudo tee -a /etc/fstab
sudo mount /mnt/shared

Windows 10 and 11 no longer show Samba servers in “Network” by themselves, because the old NetBIOS browsing is gone. Install wsdd (Web Services Discovery) on the server and the computer appears in the network list again: sudo apt install wsdd.

Security settings worth enabling

  • SMB1 is off by default since Samba 4.11. Do not turn it back on: it is the protocol WannaCry used. Old devices that need SMB1 should be replaced or isolated.
  • Encryption: add server smb encrypt = required to [global] to encrypt all traffic (supported by Windows 8 and newer, macOS and Linux).
  • Never open port 445 to the internet. To reach the share from outside, connect through a VPN such as WireGuard and keep Samba bound to the local network: interfaces = lo 192.168.1.0/24 and bind interfaces only = yes.
  • Separate users and folders instead of one shared password for everyone.

Samba on a VPS

A Samba share on a rented server is handy for off-site backups or a shared folder for a remote team, as long as it is reached only through a VPN. For that you need a plan with a large disk rather than a fast CPU; DIEG Finder filters VPS and storage plans by disk size, location and price.

Troubleshooting

ProblemWhat to check
Access deniedUser in the group, smbpasswd -e, folder permissions, SELinux label
Share not visible in WindowsInstall wsdd, or connect directly by \\IP\share
Windows refuses guest accessWindows 11 blocks insecure guest logons by default — use a user and password
Files created with wrong permissionscreate mask, directory mask and the setgid bit (2770) on the folder
Connection slow or dropsCheck the network first; logs are in /var/log/samba/

Need to see which client holds a file open on the server? sudo smbstatus lists connections and locked files, and lsof shows which process keeps it.

FAQ

What is the difference between Samba and NFS?

NFS is the native file sharing of Linux and Unix and works best between Linux machines. Samba speaks SMB, which Windows and macOS understand out of the box. In mixed networks Samba is the simpler choice.

Which ports does Samba use?

TCP 445 for SMB. Ports 137–139 are needed only for old NetBIOS clients, and wsdd uses UDP 3702 and TCP 5357 for discovery.

🛠️ Top Temporary VPS for Testing & Experiments (2026)

Need a fast cloud server for a few hours or days? Deploy an isolated testing environment, run your scripts, and destroy it without any monthly commitments. Secure payments via Crypto (USDT) & PayPal supported.

AÉZA — Ultimate Testing Environment • Flexible rates: from €0.01/hr depending on the billing period (the longer you rent, the cheaper it gets).
• Exclusive Welcome Bonus: Get an extra 15% on your first balance top-up within 24 hours after registration.
Deploy on Aeza
Friendhosting — High-Storage VDS • Hourly VDS infrastructure (from €0.03/hr) deployed across massive global locations.
• Best-in-class Storage VDS configurations with huge disk space for heavy data testing.
Deploy on Friend
Zomro — Premium Daily Node • Daily billing model starting at just €0.16/day (~€0.007/hr) for optimal cost control.
• High-speed hardware platform with a stable presence in the Netherlands (Europe).
Deploy on Zomro
Rork

Linux hobbyist into networking and digital privacy. I use this hub to translate and store technical notes on sysadmin tasks and anonymity tools. Tech should work for people, not the other way around.

Rate author
Add a comment