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:
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.
22 (default SSH port). If you plan to use a custom port, note it for later.sshd built‑in; Windows users can enable the OpenSSH Server feature or install Cygwin with the openssh package.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.
termux-setup-storage
This creates a /storage/emulated/0 link inside Termux, letting rsync read/write your normal files.
termux-setup-storage you’ll see a permission dialog. Accept it, otherwise rsync won’t see your photos, downloads, etc.sshd is installed:
sudo apt-get install openssh-server # Debian/Ubuntu
sudo systemctl enable ssh && sudo systemctl start ssh # start service
ip addr show | grep inet
Look for an address like 192.168.1.42 on the wlan0 or eth0 interface.
powershell -Command "Start-Service sshd"
ipconfig in Command Prompt; look for the IPv4 Address under your Wi‑Fi adapter.
Using key‑based authentication avoids typing passwords for every rsync run and is more secure.
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).
cat ~/.ssh/id_ed25519.pub
~/.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.
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
id_ed25519) with anyone. Only the public key (.pub) is safe to copy.ssh -i ~/.ssh/id_ed25519 user@PC_IP
Replace user with your PC username and PC_IP with the address you noted earlier.
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.
Let’s copy a folder of photos from Android to the PC’s ~/AndroidBackups/Photos directory.
mkdir -p ~/AndroidBackups/Photos
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.
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.
If you want a nightly backup without manual intervention, you can create a simple shell script in Termux and schedule it with crontab.
~/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
cronie (a lightweight cron implementation) inside Termux:
pkg install cronie
crontab -e
Add a line to run the script at 2 AM every day:
0 2 * * * ~/backup_photos.sh >> ~/backup.log 2>&1
sv-enable crond && sv up crond
(Termux uses sv to control services.)
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).
cat ~/.ssh/id_ed25519.pub on Android vs the line in authorized_keys).chmod 600 ~/.ssh/authorized_keys is required; Windows does not enforce permissions but the file must be plain text.DCIM, Download, or the Termux‑linked /storage/emulated/0.adb backup or root, which is outside the scope of this tutorial.-z (compression) flag if your network is fast; compression can actually add CPU overhead on older devices.-e "ssh -p 2222 -i ~/.ssh/id_ed25519".ssh-agent (available via pkg install openssh) if you run the backup manually and can type the passphrase each time.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!









