SSH, SCP, and RSYNC
SSH, SCP, and RSYNC
Follow this guide to generate a key pair. Here is what you can do with it (with no apps and no wires).
Requirements
- OpenSSH
- Knowing your IP addresses (
ifconfig
orip addr|grep inet
) - Your phone and laptop on the same network (e.g. hotspot on the phone)
- Turning on the sshd daemon
SSH
You can access and edit files on your phone from your computer using secure shell (SSH),
ssh 192.168.x.x -p 8022
Note: I use port 8022 in these examples (for Termux app on the phone). Other apps might be using other ports, e.g. SSHelper app uses port 2222.
SCP
You can ransfer files back and forth using secure copy (SCP),
scp -P 8022 SOURCE DESTINATION
here is how you send a copy to your phone
scp -P 8022 FILE 192.168.x.x:
here is how to send a file to your laptop from the phone
scp FILE USER@192.168.x.x:
RSYNC
And, you can sync your phone data using remote sync (RSYNC).
rsync -av -e "ssh -p 8022" SOURCE DESTINATION
From the phone to a folder called myfiles
on the computer:
rsync -av -e "ssh -p 8022" 192.168.x.x:~/ ~/myfiles/
From the computer to the phone:
rsync -av -e "ssh -p 8022" ~/myfiles/ 192.168.x.x:~/
Turning on sshd
- Termux & Linux:
sshd
command - Macs: Settings > Sharing > Remote Login (turn on)
Windows
The Windows way to do ssh is through the PuTTy program, it will enable you to log into Unix computers (macs, Androids, Linuxes..) but not the other way around and you won’t be able to do an rsync (except maybe through cygwin, which I haven’t tried). If you are looking for a great folder synchronization tool for Windows, try DSynchrnonize.