Secure Android‑PC File Transfers with Rsync over SSH

13 min read Learn step‑by‑step how to set up Rsync over SSH on Android using Termux, enabling fast, encrypted file transfers to your PC without root. September 28, 2026 12:30 How to Transfer Files Securely Between Android and PC with Rsync over SSH

Transferring large batches of photos, documents, or backup archives between your Android phone and a desktop can be slow, insecure, or require cloud services you don’t trust. By pairing rsync with an SSH tunnel you get three benefits:

  • Encryption – all traffic is wrapped in SSH, protecting it from Wi‑Fi snooping.
  • Delta transfers – rsync only moves the parts of files that changed, saving bandwidth.
  • Cross‑platform – works with Linux, macOS, and Windows (via WSL or Cygwin).

This guide assumes you have a modern Android device (Android 9+), a PC on the same local network, and a willingness to use a terminal. No root access is required.

Before You Start

  • Charge both devices or keep them plugged in – a lost connection mid‑transfer can corrupt files.
  • Make sure your Wi‑Fi router allows traffic on port 22 (default SSH port). If you plan to use a custom port, note it for later.
  • On Android, disable battery‑optimisation for Termux (Settings ▶ Apps ▶ Termux ▶ Battery ▶ Allow background activity) so the SSH client isn’t killed during long transfers.
  • On the PC, have an SSH server ready. Linux/macOS have sshd built‑in; Windows users can enable the OpenSSH Server feature or install Cygwin with the openssh package.

Step 1 – Install Termux and Required Packages

  1. Open the Termux app from F‑Droid (or the Play Store). Using F‑Droid ensures you get the most up‑to‑date, open‑source build.
  2. Update the package repository and install the tools:
    pkg update && pkg upgrade -y
    pkg install openssh rsync termux-api -y
    Why? openssh provides the SSH client, rsync does the file sync, and termux-api lets us access Android storage safely.
  3. Grant Termux access to your shared storage:
    termux-setup-storage
    This creates a /storage/emulated/0 link inside Termux, letting rsync read/write your normal files.
Note: The first time you run termux-setup-storage you’ll see a permission dialog. Accept it, otherwise rsync won’t see your photos, downloads, etc.

Step 2 – Prepare the SSH Server on Your PC

Linux/macOS

  1. Open a terminal and ensure sshd is installed:
    sudo apt-get install openssh-server   # Debian/Ubuntu
    sudo systemctl enable ssh && sudo systemctl start ssh   # start service
  2. Find your PC’s local IP address:
    ip addr show | grep inet
    Look for an address like 192.168.1.42 on the wlan0 or eth0 interface.

Windows 10/11

  1. Open Settings ▶ Apps ▶ Optional features, click Add a feature**, and install **OpenSSH Server**.
  2. Start the service:
    powershell -Command "Start-Service sshd"
  3. Find the IP address with ipconfig in Command Prompt; look for the IPv4 Address under your Wi‑Fi adapter.
Tip: If your router blocks port 22, you can change the SSH server’s listening port (e.g., 2222) and use the same port in the Android commands.

Step 3 – Create an SSH Key Pair on Android

Using key‑based authentication avoids typing passwords for every rsync run and is more secure.

  1. Generate a key pair inside Termux:
    ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
    Explanation: -t ed25519 creates a modern, compact key; -N "" leaves the passphrase empty for automated scripts (you can add a passphrase if you prefer extra security).
  2. Display the public key and copy it:
    cat ~/.ssh/id_ed25519.pub
  3. On your PC, add the key to ~/.ssh/authorized_keys (Linux/macOS) or C:\Users\YourUser\.ssh\authorized_keys (Windows). For example, on Linux:
    mkdir -p ~/.ssh
    cat >> ~/.ssh/authorized_keys
    Paste the Android public key line, then save and close.
  4. Set correct permissions on the PC side (Linux/macOS):
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
Warning: Never share your private key (id_ed25519) with anyone. Only the public key (.pub) is safe to copy.

Step 4 – Test the SSH Connection from Android

  1. In Termux, run:
    ssh -i ~/.ssh/id_ed25519 user@PC_IP
    Replace user with your PC username and PC_IP with the address you noted earlier.
  2. If the connection succeeds, you’ll see a shell prompt from the PC. Type exit to return to Termux.

If you receive Permission denied (publickey), double‑check that the public key was correctly appended to authorized_keys and that the file permissions are set as shown.

Step 5 – Perform a First Rsync Transfer

Let’s copy a folder of photos from Android to the PC’s ~/AndroidBackups/Photos directory.

  1. Create the destination folder on the PC (Linux/macOS example):
    mkdir -p ~/AndroidBackups/Photos
  2. Run rsync from Termux:
    rsync -avz -e "ssh -i ~/.ssh/id_ed25519" /storage/emulated/0/DCIM/Camera/ user@PC_IP:~/AndroidBackups/Photos/
    Options explained:
    • -a – archive mode (preserves timestamps, permissions).
    • -v – verbose, shows progress.
    • -z – compresses data during transfer, useful on slower Wi‑Fi.
    • -e "ssh -i ..." – tells rsync to use SSH with the specific key.
  3. Watch the output. Each file transferred will be listed; at the end you’ll see a summary of total bytes and speed.

After the command finishes, verify on the PC that the files appear in ~/AndroidBackups/Photos. The first run copies everything; subsequent runs will only transfer new or changed files.

Step 6 – Automate Repeated Backups (Optional)

If you want a nightly backup without manual intervention, you can create a simple shell script in Termux and schedule it with crontab.

  1. Create a script file, e.g., ~/backup_photos.sh:
    #!/data/data/com.termux/files/usr/bin/bash
    RSYNC_OPTS="-avz"
    SRC="/storage/emulated/0/DCIM/Camera/"
    DEST="user@PC_IP:~/AndroidBackups/Photos/"
    ssh -i ~/.ssh/id_ed25519 user@PC_IP "mkdir -p ~/AndroidBackups/Photos"
    rsync $RSYNC_OPTS -e "ssh -i ~/.ssh/id_ed25519" "$SRC" "$DEST"
    
    Make it executable:
    chmod +x ~/backup_photos.sh
  2. Install cronie (a lightweight cron implementation) inside Termux:
    pkg install cronie
  3. Edit the crontab:
    crontab -e
    Add a line to run the script at 2 AM every day:
    0 2 * * * ~/backup_photos.sh >> ~/backup.log 2>&1
  4. Start the cron daemon:
    sv-enable crond && sv up crond
    (Termux uses sv to control services.)
Note: Cron jobs run in the background; ensure Termux isn’t restricted by battery‑optimisation, otherwise the daemon may be killed.

Step 7 – Transfer Files from PC to Android (Reverse Direction)

Rsync works both ways. To pull a folder from the PC to Android’s Downloads directory:

rsync -avz -e "ssh -i ~/.ssh/id_ed25519" user@PC_IP:~/SharedFolder/ /storage/emulated/0/Download/

The same options apply. If you encounter “permission denied” on Android, check that the target directory is writable (Termux’s storage link gives you write access to the public external storage).

Troubleshooting Common Issues

1. Connection timed out or “ssh: connect to host … port 22: Connection refused”

  • Confirm both devices are on the same Wi‑Fi network.
  • Check the PC’s firewall – allow inbound connections on port 22 (or your custom port).
  • Verify the IP address; some routers assign different subnets to 2.4 GHz vs 5 GHz bands.

2. “Permission denied (publickey)”

  • Make sure the public key on the PC matches the private key you’re using on Android (cat ~/.ssh/id_ed25519.pub on Android vs the line in authorized_keys).
  • On Linux/macOS, chmod 600 ~/.ssh/authorized_keys is required; Windows does not enforce permissions but the file must be plain text.

3. Rsync reports “file has vanished” or “permission denied”

  • Android’s scoped storage may block access to certain app‑private directories. Stick to shared locations like DCIM, Download, or the Termux‑linked /storage/emulated/0.
  • If you need to access an app‑private folder, you’ll have to use adb backup or root, which is outside the scope of this tutorial.

4. Slow transfer speeds

  • Ensure you’re on a 5 GHz Wi‑Fi band; 2.4 GHz can be congested.
  • Remove the -z (compression) flag if your network is fast; compression can actually add CPU overhead on older devices.

Security Best Practices

  • Never expose your Android device’s SSH client to the internet. This tutorial uses the client only, which initiates outbound connections, making it safe.
  • If you must use a custom SSH port on the PC, update the rsync command accordingly, e.g., -e "ssh -p 2222 -i ~/.ssh/id_ed25519".
  • Consider adding a passphrase to the Android private key and using ssh-agent (available via pkg install openssh) if you run the backup manually and can type the passphrase each time.

Wrapping Up

By following these steps you now have a reliable, encrypted pipeline for moving files between Android and your PC. Rsync’s delta algorithm means subsequent syncs are lightning‑fast, while SSH guarantees that no one on the same Wi‑Fi can sniff your data. Because everything runs in user space, you can keep your device unrooted and still enjoy the efficiency of a true file‑sync tool.

Feel free to adapt the script paths, schedule, or even integrate it with cloud storage (e.g., rsync to a remote server) once you’re comfortable with the basics. Happy syncing!

User Comments (0)

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