# SMB

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

---

## Server

1.  ### Install

    Install the SMB server package to enable file sharing.

    ```sh
    sudo apt update && sudo apt install samba -y
    ```

2.  ### Set SMB password

    Samba uses its own password database. It must be set manually, even if it’s the same as your login password.

    ```sh
    sudo smbpasswd -a {{USERNAME_VAR}}
    ```

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

    ```sh
    sudo smbpasswd -e {{USERNAME_VAR}}
    ```

3.  ### smb.conf

    ```sh
    sudo nano /etc/samba/smb.conf
    ```

    ```yml title="/etc/samba/smb.conf"
    [shared]
       path = {{SMB_SHARE_VAR}}
       read only = no
       browsable = yes
       guest ok = no
    ```

4.  ### Restart service

    ```sh
    sudo systemctl restart smbd
    ```

    Optionally enable on boot:

    ```sh
    sudo systemctl enable smbd
    ```

5.  ### Allow through firewall (optional)

    Allow Samba UDP ports (NetBIOS).

    ```sh
    sudo ufw allow from {{SUBNET_VAR}} to any port 137,138 proto udp
    ```

    Allow Samba TCP ports (SMB).

    ```sh
    sudo ufw allow from {{SUBNET_VAR}} to any port 139,445 proto tcp
    ```

## Client

1.  ### Access share

    ```txt
    smb://{{SERVER_IP_VAR}}/shared
    ```

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

    ```txt
    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.  ### Connect via terminal (temporary)

    Install required packages for terminal access:

    ```sh
    sudo apt install smbclient cifs-utils -y
    ```

    ```sh
    smbclient //{{SERVER_IP_VAR}}/shared -U {{USERNAME_VAR}}
    ```
