Jun 14, 2019 // posted on
This is a guide to setting up rsync
on Android and Linux. I use this to sync
music and it has served me well.
openssh
and rsync
on both devices. Praise be to package managers.passwd
to have a password.termux-setup-storage
to grant Termux access to your
phone's storage.The device being ssh
'd into needs to have the daemon running. I prefer to run
it on my phone.
sshd
to start the daemon.killall sshd
to kill it. (RIP)On Termux, sshd
defaults to port 8022. The network addresses can be
identified via ip a
.
Extensive documentation on ssh
for Termux is available on the wiki page.
To generate ssh
keys on either device, run the following command:
ssh-keygen [-t rsa] [-b 4096]
Default location for ssh
stuff is ~/.ssh/
.
id_rsa
is the private key. Never share this with anyone.id_rsa.pub
is your public key.authorized_keys
is a list of public keys are the allowed to ssh
into the
device.known_hosts
is a list of known hosts that have been previously ssh
'd
into.Here is a tidy high-level explanation to public-private asymmetrical key pairs.
This makes life ridiculously convenient.
To copy a device's public key to a target:
ssh
daemon running.ssh-copy-id [-p <port>] <target_address>
I wasn't able to copy my public key from my computer to my phone without having
run passwd
on my phone.
This can also be done manually. The goal is to append destination's
~/.ssh/id_rsa.pub
to target's ~/.ssh/authorized_keys
as a single line.
Try ssh
ing into a device like so:
$ ssh [-p 8022] <target_address>
Ayy we did it! (Hopefully.)
rsync - a fast, versatile, remote (and local) file-copying tool
It is a great tool. I love it.
The command that I run on my computer looks like this:
$ rsync --recursive --verbose --progress --ignore-existing\
[--delete]\
-e 'ssh -p 8022'\
~/Music/synced_music/\
<phone_address>:/sdcard/Music/synced_music
--delete
deletes files that I have deleted on my computer./
. This is intended. Different behaviours are
exhibited with and without it:
/
suffixed, rsync
makes sure destination and target are synced./
, rsync
copies destination into target.From here on, everything can be configured and automated to any extent. For
example, I have a function called musicsync
in my
.zshrc
(RAW).
This whole thing is a hack with a downside. sshd
is notoriously slow over
local WiFi connections. See
HERE and
HERE.
This isn't too big a deal when the transfer size is small but, otherwise, it can
be frustrating.
Github user Neo-oli has suggested workarounds HERE . I'll copy and paste them here for convenience.
Run adb forward tcp:8022 tcp:8022
to forward the phone's port to localhost's
port.
ssh someserver -t -- "while true;do sleep 0.1; date;done";
If ssh
and rsync
do not float your rafter (cries), other options are
available:
adb
, packaged with android-tools
, on most distros, has sync, pull and
push options and can be used over the network. (I think.)android-file-transfer
is available on most distros but is rudimentary.mtpfs
allows mounting MTP devices as file systems.EDIT: Much better ha!