Many Android users need a quick way to pull files from their phone without using cloud services or USB cables. An SFTP (SSH File Transfer Protocol) server gives you encrypted, password‑protected access over Wi‑Fi or a LAN, and you can reach the device from any desktop, laptop, or another Android phone.
Termux:Boot app from F‑Droid if you want the server to start automatically after reboot.pkg update && pkg upgrade -y
This may take a few minutes.
pkg install openssh
ssh -V
You should see something like OpenSSH_8.9p1, OpenSSL 1.1.1k.
Running the SSH daemon as the default u0_aXXX Android user gives the server full access to your phone, which is risky. Instead, we create a restricted user that can only see a specific folder.
sftpuser:
adduser sftpuser
Termux will ask for a password and some optional details. Choose a strong password.
/data/data/com.termux/files/home/sftp_share:
mkdir -p ~/sftp_share
sftpuser can read/write inside the share:
chown sftpuser:sftpuser ~/sftp_share
photos, documents).The default sshd_config allows full shell access. We will edit it to limit the new user to SFTP and jail them to the share directory.
nano (install it if needed with pkg install nano):
nano $PREFIX/etc/ssh/sshd_config
#Subsystem sftp /data/data/com.termux/files/usr/libexec/sftp-server and uncomment it (remove the leading #):
Subsystem sftp /data/data/com.termux/files/usr/libexec/sftp-server
sftpuser:
Match User sftpuser
ChrootDirectory %h/sftp_share
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
PasswordAuthentication yes
Explanation:
sftp_share folder.OpenSSH needs a set of host keys to identify the server. The first time you start sshd, it will create them automatically, but you can also generate them manually.
ssh-keygen -A
This creates RSA, ECDSA, and ED25519 keys in $PREFIX/etc/ssh/.
sshd
If you see no output, the daemon started successfully.
ip addr show wlan0
Look for the line containing inet, e.g., 192.168.1.42/24. The part before the slash is your device’s IP.
ssh sftpuser@192.168.1.42
You should be prompted for the password you set earlier. If you see a “Permission denied” error, double‑check the password and the sshd_config changes.
Any standard SFTP client works (FileZilla, WinSCP, Cyberduck, or the sftp command line).
192.168.1.42 (replace with your device’s IP)22 (default SSH port)SFTP – SSH File Transfer ProtocolNormalsftpusersftp_share. You can now drag‑and‑drop files, create folders, or delete items.
If you want the SFTP server to be available after a reboot without manually typing sshd, use the Termux:Boot add‑on.
Termux:Boot from F‑Droid.
~/.termux/boot (create the folder if it doesn’t exist):
mkdir -p ~/.termux/boot
cat > ~/.termux/boot/start-sftp.sh <<'EOF'
#!/data/data/com.termux/files/usr/bin/sh
sshd
EOF
chmod +x ~/.termux/boot/start-sftp.sh
ps aux | grep sshd shows the daemon running.
Running a password‑based SFTP server is convenient, but key‑based authentication is more secure.
ssh-keygen -t ed25519 -C "android-sftp"
Accept the default file location (e.g., ~/.ssh/id_ed25519) and set a passphrase.
.ssh folder for sftpuser:
mkdir -p /data/data/com.termux/files/home/.ssh
authorized_keys:
echo "$(cat ~/.ssh/id_ed25519.pub)" >> /data/data/com.termux/files/home/.ssh/authorized_keys
chmod 600 /data/data/com.termux/files/home/.ssh/authorized_keys
Edit $PREFIX/etc/ssh/sshd_config again and change the line PasswordAuthentication yes to PasswordAuthentication no. Restart the daemon:
pkill sshd
sshd
Now only clients with the matching private key can log in.
sshd_config before editing. You can restore it with cp $PREFIX/etc/ssh/sshd_config.backup $PREFIX/etc/ssh/sshd_config.sshd is running (ps | grep sshd) and that you are using the correct IP address. Wi‑Fi isolation on some routers prevents devices from seeing each other; disable AP‑isolation.Match User sftpuser block – a stray space or typo can cause the daemon to ignore the rule.sftp_share) must be owned by root for OpenSSH to accept the chroot. In Termux, the closest equivalent is the user that started the daemon. If you get “Bad owner or permissions” when starting sshd, change ownership:
chown root:root ~/sftp_share
Then create a sub‑folder owned by sftpuser for read/write access:
mkdir ~/sftp_share/incoming
chown sftpuser:sftpuser ~/sftp_share/incoming
termux-wake-lock command before starting sshd to keep the CPU awake:
termux-wake-lock
sshd
Remember to release the lock later with termux-wake-unlock.Replace the ForceCommand internal-sftp line with:
ForceCommand internal-sftp -u 022
The -u 022 flag sets a default umask that removes write permission for the user.
For remote access you can forward port 22 through your home router’s NAT. This involves setting up a port‑forward rule (e.g., external port 2222 → internal IP 192.168.1.42 port 22). Never expose the server without key‑based authentication and a strong firewall rule.
Editing Port 22 in sshd_config to something like Port 2222 reduces automated scans. Remember to update your client configuration accordingly.
When you no longer need the SFTP server:
pkill sshd.
deluser sftpuser
rm -rf ~/sftp_share
pkg uninstall openssh
By the end of this tutorial you should be able to:
sshd_config for SFTP‑only access.With a lightweight SFTP server on your phone you gain a flexible, encrypted file‑sharing method that works on any network, respects Android’s sandbox, and requires no special permissions beyond what Termux already provides.









