Using rsync over LAN with an Android phone

Prep work:

  1. Have your phone connected to your LAN - WIFI on
  2. Have the app SimpleSSHD installed on your phone and running

On the Phone

  1. Open SimpleSSHD and go to settings via the kabab menu
  2. Note the Port Number
    • In my case it was set to 2222
  3. Note (write down) the SSH Path
    • in my case it was /data/user/0/org.galexander.sshd/files
  4. Set the Home Directory to: sdcard
  5. Return to the main screen of SimpleSSHD
  6. Note the ip address of the phone on the main screen of SimpleSSHD
    • in my case it was 192.168.1.112

On your computer

  1. Open a terminal
  2. ssh into your phone using the port and ip address from above
    • ssh -p 2222 192.168.1.112
  3. When prompted to allow this connection, type: yes and hit enter

On the phone

  1. On the main screen of SimpleSSHD a single-use password is displayed

On your computer

  1. Enter the password that is displayed on SimpleSSHD
  2. You are now logged in to your phone via an ssh terminal. Have a look around with ls -l and cd and note the directory structure.
    • in my case the photos are located (starting at sdcard) in DCIM/Camera
  3. Type exit [enter] to end the ssh session
  4. Confirm the existence of your public ssh key on your computer with
    • cat ~/.ssh/id_rsa.pub
  5. If the key was not found, generate one with
    • ssh-keygen -t rsa -b 4096
    • accept the prompt for location
    • don’t use a password – leave blank
    • do #16 again
  6. Add the port 2222 for the phone’s ip address to your ssh config file with these commands:
    • echo “Host [ip addres of the phone]” >> ~/.ssh/config
      • echo “Host 192.168.1.112” >> ~/.ssh/config
    • echo “Port [port of the phone]” >> ~/.ssh/config
      • echo “Port 2222” >> ~/.ssh/config
  7. Copy your id_rsa.pub key to the phone using secure copy with
    • scp ~/.ssh/id_rsa.pub [ip address of the phone]:[ssh path on the phone]/authorized_keys
    • in my case it was:
      • scp ~/.ssh/id_rsa.pub 192.168.1.112:/data/user/0/org.galexander.sshd/files/authorized_keys

On the phone

  1. SimpleSSHD now displays a newly generated, single-use password

On your computer

  1. Enter the password that is displayed on SimpleSSHD
  2. You should now be able to login to your phone with
    • ssh 192.168.1.112

rsync command to copy pictures from your phone

  1. rsync --verbose --ignore-existing --dry-run 192.168.1.112:DCIM/Camera/* ~/Pictures
    • #23 is with the --dry-run option. No action is actually performed
  2. rsync --verbose --ignore-existing 192.168.1.112:DCIM/Camera/* ~/Pictures

rsync command to push audio files to your phone

  1. rsync --verbose --ignore-existing --dry-run ~/path/to/my/audio/* 192.168.1.112:Music
    • #25 is with the --dry-run option. No action is actually performed
  2. rsync --verbose --ignore-existing ~/path/to/my/audio/* 192.168.1.112:Music

Here is how I am using this.

I set the SimpleSSHD app to be fired by Tasker (Android scheduling app) every morning. I set a cron event on my computer to grab my new pictures from my phone. I set another cron event on my computer to push my new podcasts that were aggregated (while I slept) onto my phone for listening during the following day. (I scripted a personal aggregator for privacy and post processing reasons).

3 Likes