Bulat Khamitov
We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Copy Files With Rsync Over SSH

PostedMarch 29, 2013 408.4k views Linux Basics

Step 1 - Setup public SSH keys

On our origin server, we will generate public SSH keys with no password:

ssh-keygen -f ~/.ssh/id_rsa -q -P ""
cat ~/.ssh/

This is our public SSH key that can be placed on other hosts to give us access:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLVDBIpdpfePg/a6h8au1HTKPPrg8wuTrjdh0QFVPpTI4KHctf6/FGg1NOgM++hrDlbrDVStKn/b3Mu65//tuvY5SG9sR4vrINCSQF++a+YRTGU6Sn4ltKpyj3usHERvBndtFXoDxsYKRCtPfgm1BGTBpoSl2A7lrwnmVSg+u11FOa1xSZ393aaBFDSeX8GlJf1SojWYIAbE25Xe3z5L232vZ5acC2PJkvKctzvUttJCP91gbNe5FSwDolE44diYbNYqEtvq2Jt8x45YzgFSVKf6ffnPwnUDwhtvc2f317TKx9l2Eq4aWqXTOMiPFA5ZRM/CF0IJCqeXG6s+qVfRjB root@cloudads

Copy this key to your clipboard and login to your destination server.

Place this SSH key into your ~/.ssh/authorized_keys file:

If your SSH folder does not exist, create it manually:

mkdir ~/.ssh
chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys
chmod 0644 ~/.ssh/authorized_keys

Step 3 - Rsync files over

Rsync is a great utility, as it allows you, among many other things, to copy files recursively with compression, and over an encrypted channel.

We will copy a file from our origin server ( in /root/bigfile.txt over to our destination server (IP: and save it in /root/bigfile.txt as well.

Login on and rsync the file over to

rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /root/bigfile.txt

If you are using a different user, for example "username" then you would have to append it in front of destination server. Make sure to have your public key in that user's ~/.ssh/authorized_keys file:

rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /root/bigfile.txt username@

The SSH options are useful to keep Rsync quiet and not prompting everytime you connect to a new server.

Verify that you have received the file on destination server (

ls -la /root/bigfile.txt

And you are all done!

By Bulat Khamitov


Creative Commons License