Skip to content
Search Fedora

    Browse this documentation

    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”.

    Terminal window
    sudo dnf install -y samba samba-client

    Measured samba 4.25.0. samba is the server; samba-client brings smbclient for debugging — install it, local verification depends on it.

    Prepare the directory and config:

    Terminal window
    sudo mkdir -p /srv/smbtest
    echo "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 = yes
    Terminal window
    sudo systemctl enable --now smb

    Pitfall 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 successful
    NT_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:

    Terminal window
    sudo semanage fcontext -a -t samba_share_t "/srv/smbtest(/.*)?"
    sudo restorecon -Rv /srv/smbtest

    Measured: the share works immediately after relabelling:

    $ smbclient //127.0.0.1/share -N -c "get hello.txt /tmp/h.txt"
    $ cat /tmp/h.txt
    hello from samba

    Anonymous read-only suits distribution; real collaboration needs accounts:

    [secure]
    path = /srv/smbtest
    read only = no
    guest ok = no
    valid users = labuser

    Setting the password — interactive smbpasswd fails in scripts (measured: Unable to get new password), use the non-interactive form:

    Terminal window
    printf "password\npassword\n" | sudo smbpasswd -s -a labuser

    Windows path: \\server-ip\secure. macOS Finder → Connect to Server → smb://server-ip/secure.

    Terminal window
    sudo dnf install -y cifs-utils
    sudo 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=labuser
    password=password
    Terminal window
    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).

    1. systemctl is-active smb
    2. smbclient //127.0.0.1/share -N -c "ls" — loopback first
    3. Access denied → ls -lZ, add samba_share_t if missing
    4. NT_STATUS_LOGON_FAILURE → wrong password or user never added with smbpasswd -a
    5. remote unreachable → firewall --add-service=samba
    SymptomCause
    Access denied even for lsSELinux label is not samba_share_t
    interactive smbpasswd hangs in scriptsuse printf "pw\npw\n" | smbpasswd -s -a user
    Windows sees the share but cannot openfilesystem permissions combined with valid users
    writes fail (read-only)read only = no missing, or filesystem mounted ro
    mojibake in filenamesclient vs unix charset mismatch; default utf-8 usually fine
    share gone after rebootsmb not enabled at boot