Copy Files Between Server With Rsync Over SSH (FTP replacement)

Dec 19, 2018

On the Source server.

ssh-keygen -b 4096cat ~/.ssh/id_rsa.pub

On the Destination server, paste the content of ~/.ssh/id_rsa.pub into ~/.ssh/authorized_keys.

nano ~/.ssh/authorized_keys

If ~/.ssh/ doesn't exist, create the directory.

mkdir ~/.sshchmod 0700 ~/.sshnano ~/.ssh/authorized_keyschmod 0644 ~/.ssh/authorized_keys

On the Source server.

rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /SOURCE USER@IP_ADDRESS:/DEST

NOTE: If SOURCE is a directory, exclude the directory name is DEST

Specify identity file without depending on ~/.ssh/id_rsa

rsync -avz -e "ssh -i IDENTITY_KEY.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /SOURCE USER@IP_ADDRESS:/DEST

Exclude files for rsync

rsync -avz -e "ssh -i IDENTITY_KEY.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /SOURCE USER@IP_ADDRESS:/DEST --exclude "*.pyc" --exclude "__pycache__" --exclude ".git" --exclude ".gitignore"

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.