Turning an Android device into an SFTP server is useful for quick file transfers, remote access to media, or lightweight backups. The method described here works on Android 8.0+ and does not require root. You will need:
scp/sftp command‑line tools.Security note: An SFTP server exposes a network port (default 2222). Keep the server on a trusted local network, use strong passwords or SSH keys, and disable the service when you are finished.
pkg update && pkg upgrade -y
This ensures you have the latest OpenSSH binaries.Why this matters: Android’s bundled binaries are often outdated. Updating guarantees you get recent security patches for OpenSSH.
pkg install opensshsshd -h
You should see the OpenSSH help output.OpenSSH provides the sshd daemon that handles SFTP connections.
adduser sftpuser
When prompted, set a strong password and accept defaults for other fields./data/data/com.termux/files/home/sftp_share:
mkdir -p /data/data/com.termux/files/home/sftp_share
chown sftpuser:sftpuser /data/data/com.termux/files/home/sftp_shareIf you prefer to keep using the default Termux user, skip this step and share the ~/ directory instead.
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
This creates a key pair without a passphrase. You can add a passphrase for extra security.authorized_keys file:
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keysid_ed25519) and import it into your SFTP client.Why keys? Password authentication can be brute‑forced if the port is exposed. Public‑key authentication is both faster and more secure.
mkdir -p $HOME/.ssh
nano $HOME/.ssh/sshd_configPort if you want a non‑standard port):
Port 2222
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
Subsystem sftp internal-sftp
# Restrict to the shared directory (optional)
Match User sftpuser
ChrootDirectory %h
ForceCommand internal-sftpCtrl+X, Y, Enter).The ChrootDirectory line locks the user to their home folder, preventing access to the rest of the device. If you skipped the dedicated user, remove the Match block.
sshd -D -e
You should see log messages indicating the server is listening on port 2222.ssh -p 2222 localhost
If you can log in, the server works.Ctrl+C.Running in the foreground helps you see errors before you set up a background service.
mkdir -p $HOME/.termux/boot
nano $HOME/.termux/boot/start-ssh.sh#!/data/data/com.termux/files/usr/bin/sh
sshd
chmod +x $HOME/.termux/boot/start-ssh.sh$HOME/.termux/boot/start-ssh.shNow the SFTP server will start automatically whenever the device boots and Termux is allowed to run in the background.
ip addr show wlan0sftpuser (or your Termux user)id_ed25519 you exported) or password if you kept password auth.If the connection fails, double‑check the firewall (see troubleshooting) and that the device is on the same subnet.
termux-wake-lock to prevent the CPU from sleeping while you need the server:
termux-wake-locktermux-wake-unlockThis is optional but handy for long transfers.
Another app may already be listening on port 2222. Change the Port line in sshd_config to an unused value (e.g., 2022) and restart the daemon.
.ssh directory and authorized_keys file have the correct permissions (700 for the folder, 600 for the file).ChrootDirectory, the chroot directory itself must be owned by root. On Android this translates to the Termux user owning the folder, so you may need to omit the ChrootDirectory line if you encounter "bad ownership" errors.Android may kill background processes to reclaim memory. Enable “Battery optimization” → “Don’t optimize” for Termux, or keep the app in the recent‑apps list.
If you prefer a GUI solution, apps like SSHelper or WiFi FTP Server bundle OpenSSH and handle service start‑up automatically. They are convenient but add another app to your system and may have ads. The Termux method gives you full control, no ads, and the ability to script custom behaviours.
sshd with pkill sshd or uninstall the boot script.pkg update && pkg upgrade.With these steps you now have a lightweight, secure SFTP server running on your Android phone. It can serve as a quick backup point, a media library, or a development sandbox without ever rooting the device.









