How to Turn Your Android Phone into a Secure SFTP Server with Termux (No Root)

9 min read Learn step‑by‑step how to install Termux, set up OpenSSH, and run a secure SFTP server on any Android device without rooting. Includes safety tips and troubleshooting. October 11, 2026 18:00 How to Turn Your Android Phone into a Secure SFTP Server with Termux (No Root)

Before you start

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:

  • A stable Wi‑Fi connection (or a USB‑tethered network).
  • At least 200 MB of free storage for the Termux app and SSH keys.
  • Termux from F-Droid (recommended) or Google Play.
  • A client device (PC, another phone, tablet) with an SFTP client such as FileZilla, WinSCP, or the 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.

Step 1 – Install Termux and update the environment

  1. Open the F-Droid store, search for Termux, and install it.
  2. Launch Termux. The first launch will download the basic runtime.
  3. Update package lists and upgrade existing packages:
    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.

Step 2 – Install the OpenSSH package

  1. In the Termux terminal, run:
    pkg install openssh
  2. Verify the installation:
    sshd -h
    You should see the OpenSSH help output.

OpenSSH provides the sshd daemon that handles SFTP connections.

Step 3 – Create a dedicated user (optional but recommended)

  1. Termux runs as the current Android user, but you can create a separate Unix user to isolate files:
    adduser sftpuser
    When prompted, set a strong password and accept defaults for other fields.
  2. Give the new user a home directory you will share, for example /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_share

If you prefer to keep using the default Termux user, skip this step and share the ~/ directory instead.

Step 4 – Generate SSH keys (recommended over passwords)

  1. Switch to the user you created (or stay as the default) and run:
    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.
  2. Copy the public key to the authorized_keys file:
    cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
  3. On the client device, export the private key (id_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.

Step 5 – Configure the SSH daemon

  1. Edit the SSH config file (create it if missing):
    mkdir -p $HOME/.ssh
    nano $HOME/.ssh/sshd_config
  2. Paste the following minimal configuration (adjust Port 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-sftp
  3. Save and exit (Ctrl+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.

Step 6 – Start the SSH daemon

  1. Run the daemon in the foreground to test:
    sshd -D -e
    You should see log messages indicating the server is listening on port 2222.
  2. Open another Termux session (swipe from left or tap the split‑screen icon) and verify connectivity from the same device:
    ssh -p 2222 localhost
    If you can log in, the server works.
  3. Stop the foreground daemon with Ctrl+C.

Running in the foreground helps you see errors before you set up a background service.

Step 7 – Run sshd as a background service

  1. Install the Termux:Boot add‑on (available on F‑Droid). This lets scripts start automatically after a reboot.
  2. Create a startup script:
    mkdir -p $HOME/.termux/boot
    nano $HOME/.termux/boot/start-ssh.sh
  3. Add the following lines:
    #!/data/data/com.termux/files/usr/bin/sh
    sshd
    
  4. Make it executable:
    chmod +x $HOME/.termux/boot/start-ssh.sh
  5. Reboot the device or run the script manually to test:
    $HOME/.termux/boot/start-ssh.sh

Now the SFTP server will start automatically whenever the device boots and Termux is allowed to run in the background.

Step 8 – Connect from a client

  1. Find the Android device’s IP address (Settings → Wi‑Fi → Tap your network → Advanced → IP address) or run in Termux:
    ip addr show wlan0
  2. On the client, open your SFTP client and create a new connection:
    • Host: Android IP
    • Port: 2222
    • Username: sftpuser (or your Termux user)
    • Authentication: Private key (the id_ed25519 you exported) or password if you kept password auth.
  3. Connect. You should see the contents of the shared folder.

If the connection fails, double‑check the firewall (see troubleshooting) and that the device is on the same subnet.

Step 9 – Keep the server alive when the screen turns off

  1. Install termux-wake-lock to prevent the CPU from sleeping while you need the server:
    termux-wake-lock
  2. When you are done, release the lock:
    termux-wake-unlock

This is optional but handy for long transfers.

Troubleshooting

1. sshd won’t start – "Address already in use"

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.

2. Permission denied when logging in

  • Ensure the .ssh directory and authorized_keys file have the correct permissions (700 for the folder, 600 for the file).
  • If you are using a dedicated user with 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.

3. Cannot connect from another device

  • Confirm both devices are on the same Wi‑Fi network.
  • Check Android’s “Private DNS” or VPN settings that might block inbound connections.
  • Some manufacturers (e.g., Samsung) enable a “Network security” feature that blocks non‑system apps from listening on ports. In Settings → Apps → Termux → Battery, set “Allow background activity”.

4. Server stops when the app is swiped away

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.

Alternative: Using a ready‑made SFTP server app

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.

Safety checklist before leaving the server running

  • Use a strong, unique password or, better, public‑key authentication.
  • Keep the device on a trusted LAN; avoid exposing port 2222 to the internet.
  • Disable the server when not needed: either stop sshd with pkill sshd or uninstall the boot script.
  • Regularly update Termux packages: 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.

User Comments (0)

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