Samba file sharing between Linux, Windows and macOS
Samba lets Windows and macOS read Linux directories directly. This page chains together every measured pitfall behind “configured the share but cannot open the file”.
Install
Section titled “Install”sudo dnf install -y samba samba-clientMeasured samba 4.25.0. samba is the server; samba-client brings smbclient for debugging — install it, local verification depends on it.
A minimal anonymous share
Section titled “A minimal anonymous share”Prepare the directory and config:
sudo mkdir -p /srv/smbtestecho "hello from samba" | sudo tee /srv/smbtest/hello.txt/etc/samba/smb.conf:
[global] server role = standalone server map to guest = Bad User
[share] path = /srv/smbtest read only = yes guest ok = yessudo systemctl enable --now smbPitfall one: Access denied is not a config error
Section titled “Pitfall one: Access denied is not a config error”With the config above and the service active, measured:
$ smbclient //127.0.0.1/share -N -c "ls"Anonymous login successfulNT_STATUS_ACCESS_DENIED listing \*Even ls is refused. testparm -s shows the config is fine, the directory is 755, the file 644 — it is SELinux. Ordinary directories are labelled var_t/user_tmp_t, which smbd may not read:
sudo semanage fcontext -a -t samba_share_t "/srv/smbtest(/.*)?"sudo restorecon -Rv /srv/smbtestMeasured: the share works immediately after relabelling:
$ smbclient //127.0.0.1/share -N -c "get hello.txt /tmp/h.txt"$ cat /tmp/h.txthello from sambaAuthenticated read-write share
Section titled “Authenticated read-write share”Anonymous read-only suits distribution; real collaboration needs accounts:
[secure] path = /srv/smbtest read only = no guest ok = no valid users = labuserSetting the password — interactive smbpasswd fails in scripts (measured: Unable to get new password), use the non-interactive form:
printf "password\npassword\n" | sudo smbpasswd -s -a labuserWindows path: \\server-ip\secure. macOS Finder → Connect to Server → smb://server-ip/secure.
Mounting from Linux (cifs)
Section titled “Mounting from Linux (cifs)”sudo dnf install -y cifs-utilssudo mount -t cifs //server-ip/secure /mnt/share -o \ username=labuser,uid=$(id -u),gid=$(id -g)For fstab, use a credentials file instead of an inline password:
//server-ip/secure /mnt/share cifs credentials=/etc/smb-cred,uid=1000,gid=1000 0 0/etc/smb-cred (mode 600):
username=labuserpassword=passwordFirewall and name discovery
Section titled “Firewall and name discovery”sudo firewall-cmd --add-service=samba --permanent && sudo firewall-cmd --reload\\IP\share in Windows Explorer always works; hostname discovery additionally needs mDNS/NetBIOS (avahi ships by default; recent Windows versions speak mDNS).
Troubleshooting order
Section titled “Troubleshooting order”systemctl is-active smbsmbclient //127.0.0.1/share -N -c "ls"— loopback first- Access denied →
ls -lZ, addsamba_share_tif missing NT_STATUS_LOGON_FAILURE→ wrong password or user never added withsmbpasswd -a- remote unreachable → firewall
--add-service=samba
Common traps
Section titled “Common traps”| Symptom | Cause |
|---|---|
Access denied even for ls | SELinux label is not samba_share_t |
interactive smbpasswd hangs in scripts | use printf "pw\npw\n" | smbpasswd -s -a user |
| Windows sees the share but cannot open | filesystem permissions combined with valid users |
| writes fail (read-only) | read only = no missing, or filesystem mounted ro |
| mojibake in filenames | client vs unix charset mismatch; default utf-8 usually fine |
| share gone after reboot | smb not enabled at boot |
Related pages
Section titled “Related pages”- SELinux — the full labelling model
- firewalld — allowing services
- journalctl —
journalctl -u smbdebugging - Upstream: Samba docs