Set Up a Local SMB File Share on Android Using Termux (No Root)

16 min read Step‑by‑step guide to turn any Android phone into a local SMB (Windows) file server using Termux and Samba, without rooting. October 14, 2026 01:30 How to Set Up a Local SMB File Share on Android with Termux (No Root)

Why you might want an SMB share on Android

SMB (Server Message Block) is the protocol Windows uses for file sharing. By turning your Android phone into an SMB server you can:

  • Access photos, videos, or documents from any PC, Mac or another Android device without cloud services.
  • Create a quick‑and‑dirty network‑attached storage (NAS) for a small office or a home lab.
  • Transfer large files over Wi‑Fi, which is often faster and more reliable than Bluetooth or USB OTG.

All of this can be done with Termux, a terminal emulator that runs a minimal Linux environment on Android, and Samba, the open‑source SMB implementation. The method works on Android 6.0+ and does not require root access.

Before you start

Prerequisites

  • Android device with at least 1 GB of free storage (Samba packages are ~30 MB).
  • Wi‑Fi connection to the same local network as the device you will connect from.
  • Termux app installed from F‑Droid (recommended) or Google Play.
  • Basic comfort with command‑line interfaces.

Do not enable this on a public Wi‑Fi network. SMB shares are unauthenticated by default unless you set a password, so anyone on the same LAN could read or write your files.

Make sure your phone is plugged into power or has at least 70 % battery, and that you have a stable Wi‑Fi connection. A reboot of the device is optional but can clear lingering services.

Step 1 – Install Termux and update the package repository

  1. Open the Termux app.
  2. Run the following commands to update the package list and upgrade existing packages:
    pkg update && pkg upgrade -y
  3. Accept any prompts. This may take a few minutes on slower devices.

Updating ensures you receive the latest pre‑compiled binaries for Samba and its dependencies.

Step 2 – Install the required packages

  1. Install openssh (provides useful utilities like ssh for testing) and samba:
    pkg install openssh samba -y
  2. Install nano (a simple text editor) if you prefer it over vim:
    pkg install nano -y

All packages are compiled for Android’s ARM or x86 architecture, so no additional configuration is needed.

Step 3 – Create a directory you want to share

  1. Decide where your shared files will live. For this tutorial we’ll use a folder called Shared inside Termux’s home directory:
    mkdir -p ~/Shared
  2. Copy a few test files into the folder so you can verify the share later:
    cp /sdcard/DCIM/Camera/*.jpg ~/Shared/

    (Replace the path with any folder that contains files you own.)

Termux runs in its own sandbox, but it can read/write any file you grant it permission to. The first time you try to access /sdcard you will be asked to allow storage access – grant it.

Step 4 – Configure Samba

Samba’s configuration file is /data/data/com.termux/files/usr/etc/samba/smb.conf. We will create a minimal configuration that defines a single share and a user account.

  1. Open the configuration file with nano:
    nano $PREFIX/etc/samba/smb.conf
  2. Replace its content with the following (copy‑paste carefully):
    [global]
       workgroup = WORKGROUP
       server string = Android SMB Server
       netbios name = AndroidPhone
       security = user
       map to guest = Bad User
       dns proxy = no
       log level = 1
       load printers = no
       printing = bsd
       disable spoolss = yes
       server role = standalone server
       passdb backend = smbpasswd
    
    [Shared]
       path = /data/data/com.termux/files/home/Shared
       browseable = yes
       read only = no
       guest ok = no
       force user = $(whoami)
       create mask = 0666
       directory mask = 0777
    

    Explanation of key directives:

    • security = user – requires a username/password for access.
    • map to guest = Bad User – any unknown user is mapped to the guest account (which we will disable).
    • guest ok = no – prevents anonymous connections.
    • force user – forces all file operations to run as the current Termux user, avoiding permission issues.
  3. Save the file (Ctrl+O, Enter) and exit (Ctrl+X).

Step 5 – Create a Samba user and set a password

  1. Run the Samba password utility. It will prompt you for a new password twice:
    smbpasswd -a $(whoami)
  2. When asked "New SMB password", type a strong password (at least 8 characters). Confirm it.
  3. Enable the account:
    smbpasswd -e $(whoami)

The user name is the same as the Termux login (usually u0_aXXX), but you can also create a friendly alias later if you prefer.

Step 6 – Start the Samba daemon

  1. Launch the Samba server in the background:
    smbd -D

    The -D flag daemonizes the process.

  2. Verify that the daemon is running:
    ps -ef | grep smbd

If you see a line containing smbd (and not the grep command), the server started successfully.

Step 7 – Test the share from another device

From a Windows PC, macOS, or another Android device with a file manager that supports SMB (e.g., CX File Explorer), follow these steps:

  • Open the file manager and choose the option to add a network location.
  • Enter the Android phone’s IP address. You can find it in Termux with ip addr show wlan0 – look for the inet line (e.g., 192.168.1.42/24).
  • Use the Samba username you created (the Termux user) and the password you set.
  • Navigate to the Shared folder. You should see the test files you copied earlier.

If the connection fails, see the troubleshooting section below.

Step 8 – (Optional) Auto‑start Samba on boot

Termux does not start services automatically after a reboot. The Termux:Boot add‑on provides a way to run scripts at boot time.

  1. Install the Termux:Boot app from F‑Droid or Play Store.
  2. Create a script that starts Samba:
    mkdir -p ~/.termux/boot
    nano ~/.termux/boot/start-samba.sh
  3. Paste the following into the script:
    #!/data/data/com.termux/files/usr/bin/sh
    # Ensure the network is up before starting Samba
    while ! ping -c1 -W1 8.8.8.8 >/dev/null 2>&1; do
      sleep 2
    done
    smbd -D
  4. Make the script executable:
    chmod +x ~/.termux/boot/start-samba.sh
  5. Reboot the device and verify that ps -ef | grep smbd shows the daemon.

The small loop waits for a working network before launching Samba, which avoids “address not available” errors on slower boots.

Step 9 – Security hardening (recommended)

  • Limit the share to a specific subnet. Add the following line inside the [global] section:
    hosts allow = 192.168.1.0/24
    Replace 192.168.1.0/24 with the CIDR of your home network.
  • Disable guest access completely. Ensure guest ok = no is present and keep map to guest = Bad User.
  • Use a strong password. A 12‑character mix of letters, numbers and symbols is advisable.
  • Firewall considerations. Android’s built‑in firewall is limited, but you can install iptables inside Termux to block external IPs if needed.

Troubleshooting

Cannot see the Android device on the network

  • Make sure Wi‑Fi is enabled and both devices are on the same subnet.
  • Check that the phone’s IP address is reachable: ping 192.168.1.42 from the client.
  • Some manufacturers (e.g., Samsung) isolate Wi‑Fi from the “network sharing” stack. In such cases enable “Allow network sharing while Wi‑Fi is off” in the device’s developer options.

Authentication fails

  • Confirm you are using the exact username printed by whoami in Termux. It may look like u0_a123.
  • If you typed the password incorrectly during smbpasswd, reset it:
    smbpasswd -r $(whoami)

Share appears empty or permission denied

  • Ensure the shared directory exists and contains files.
  • The force user = $(whoami) line in smb.conf forces all file operations to run as the Termux user, which owns the ~/Shared folder. If you changed the folder location, adjust the path accordingly.
  • Run chmod -R 777 ~/Shared as a last resort to rule out permission issues (not recommended for production use).

Samba daemon crashes immediately

  • Check the log file at $PREFIX/var/log/samba/log.smbd for error messages.
  • Common cause: missing hosts allow line with an invalid CIDR. Remove or correct it.

Advanced optional tweaks

  • Expose multiple shares. Add another block like [Photos] with its own path.
  • Read‑only shares. Set read only = yes for folders you don’t want remote devices to modify.
  • Integrate with Android’s MediaStore. Point a share to /sdcard/Movies to make media files instantly visible on a TV using SMB.

What you have achieved

By following this guide you now have a fully functional SMB server running on an Android phone without any root modifications. You can:

  • Browse, copy, edit, and delete files from any SMB‑capable client on the same LAN.
  • Start the service manually or let it launch automatically after each reboot.
  • Control access through a dedicated username/password and optional subnet restrictions.

This setup is ideal for temporary file transfers, quick backups, or as a lightweight NAS for a single‑room environment. For larger deployments consider a dedicated hardware NAS, but the Android solution remains a handy, portable alternative.

Next steps

Now that you have a share, you might want to explore:

  • Mounting the SMB share directly in Termux (apt install cifs-utils and mount -t cifs //192.168.1.42/Shared /data/data/com.termux/files/home/mnt).
  • Automating backups of the shared folder to a cloud service using rclone.
  • Running a lightweight web server (e.g., python -m http.server) alongside Samba for HTTP access.

Enjoy the flexibility of turning any Android device into a network file hub – all without rooting, flashing, or installing third‑party server apps.

User Comments (0)

Add Comment
We'll never share your email with anyone else.