SMB (Server Message Block) is the protocol Windows uses for file sharing. By turning your Android phone into an SMB server you can:
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.
Prerequisites
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.
pkg update && pkg upgrade -y
Updating ensures you receive the latest pre‑compiled binaries for Samba and its dependencies.
openssh (provides useful utilities like ssh for testing) and samba:
pkg install openssh samba -y
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.
Shared inside Termux’s home directory:
mkdir -p ~/Shared
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.
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.
nano:
nano $PREFIX/etc/samba/smb.conf
[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:
smbpasswd -a $(whoami)
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.
smbd -D
The -D flag daemonizes the process.
ps -ef | grep smbd
If you see a line containing smbd (and not the grep command), the server started successfully.
From a Windows PC, macOS, or another Android device with a file manager that supports SMB (e.g., CX File Explorer), follow these steps:
ip addr show wlan0 – look for the inet line (e.g., 192.168.1.42/24).Shared folder. You should see the test files you copied earlier.If the connection fails, see the troubleshooting section below.
Termux does not start services automatically after a reboot. The Termux:Boot add‑on provides a way to run scripts at boot time.
Termux:Boot app from F‑Droid or Play Store.mkdir -p ~/.termux/boot
nano ~/.termux/boot/start-samba.sh
#!/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
chmod +x ~/.termux/boot/start-samba.sh
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.
[global] section:
hosts allow = 192.168.1.0/24
Replace 192.168.1.0/24 with the CIDR of your home network.guest ok = no is present and keep map to guest = Bad User.
iptables inside Termux to block external IPs if needed.ping 192.168.1.42 from the client.whoami in Termux. It may look like u0_a123.smbpasswd, reset it:
smbpasswd -r $(whoami)
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.chmod -R 777 ~/Shared as a last resort to rule out permission issues (not recommended for production use).$PREFIX/var/log/samba/log.smbd for error messages.hosts allow line with an invalid CIDR. Remove or correct it.[Photos] with its own path.
read only = yes for folders you don’t want remote devices to modify.
/sdcard/Movies to make media files instantly visible on a TV using SMB.
By following this guide you now have a fully functional SMB server running on an Android phone without any root modifications. You can:
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.
Now that you have a share, you might want to explore:
apt install cifs-utils and mount -t cifs //192.168.1.42/Shared /data/data/com.termux/files/home/mnt).rclone.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.









