Copy Files Between Server With Rsync Over Ssh

July 29, 2019

On the Source server.

ssh-keygen -b 4096
cat ~/.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 ~/.ssh
chmod 0700 ~/.ssh
nano ~/.ssh/authorized_keys
chmod 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 -f IDENTITY_KEY.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /SOURCE USER@IP_ADDRESS:/DEST

Exclude files for rsync

rsync -avz -e "ssh -f IDENTITY_KEY.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /SOURCE USER@IP_ADDRESS:/DEST --exclude "*.pyc" --exclude "__pycache__" --exclude ".git" --exclude ".gitignore"
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.