Skip to content

SMB

Setup guide for sharing files over a local network using Samba (SMB/CIFS) between Linux and other devices.



  1. Install the SMB server package to enable file sharing.

    Terminal window
    sudo apt update && sudo apt install samba -y
  2. Samba uses its own password database. It must be set manually, even if it’s the same as your login password.

    Terminal window
    sudo smbpasswd -a {{USERNAME_VAR}}

    Enable the user (usually automatic, but safe to ensure):

    Terminal window
    sudo smbpasswd -e {{USERNAME_VAR}}
  3. Terminal window
    sudo nano /etc/samba/smb.conf
    /etc/samba/smb.conf
    [shared]
    path = {{SMB_SHARE_VAR}}
    read only = no
    browsable = yes
    guest ok = no
  4. Terminal window
    sudo systemctl restart smbd

    Optionally enable on boot:

    Terminal window
    sudo systemctl enable smbd
  5. Allow Samba UDP ports (NetBIOS).

    Terminal window
    sudo ufw allow from {{SUBNET_VAR}} to any port 137,138 proto udp

    Allow Samba TCP ports (SMB).

    Terminal window
    sudo ufw allow from {{SUBNET_VAR}} to any port 139,445 proto tcp
  1. smb://{{SERVER_IP_VAR}}/shared

    Or using hostname (if mDNS/Avahi is working):

    smb://{{HOSTNAME_VAR}}.local/shared

    Notes:

    • Replace shared with your share name.
    • .local requires Avahi (avahi-daemon) on the server and client.
    • If hostname does not resolve, use the server IP instead.

  2. Install required packages for terminal access:

    Terminal window
    sudo apt install smbclient cifs-utils -y
    Terminal window
    smbclient //{{SERVER_IP_VAR}}/shared -U {{USERNAME_VAR}}