docs / linux / rsync-with-ssh-key
rsync with ssh key
On our origin server, we will generate public SSH keys with no password:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -q -N "" -C "your@email.here"cat ~/.ssh/id_rsa.pubThis is our public SSH key that can be placed on other hosts to give us access:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLVDBIpdpfePga6h8au1HTKPPrg8wuTrjdh0QFVPpTI4KHctf6FGg1NOg+hrDlbrDVStKb3Mu65tuvY5SG9sR4vrINCSQF+a+YRTGU6Sn4ltKpyj3usHERvBndtFXoDxsYKRCtPfgm1BGTBpoSl2A7lrwnmVSg+u11FOa1xSZ393aaBFDSeX8GlJf1SojWYIAbE25Xe3z5L232vZ5acC2PJkvKctzvUttJCP91gbNe5FSwDolE44diYbNYqEtvq2Jt8x45YzgFSVKf6ffnPwnUDwhtvc2f317TKx9l2Eq4aWqXTOMiPFA5ZRMCF0IJCqeXG6s+qVfRjBroot@cloudadsCopy 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_keysStep 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 (198.211.117.101) in /root/bigfile.txt over to our destination server (IP: 198.211.117.129) and save it in /root/bigfile.txt as well.
Login on 198.211.117.101 and rsync the file over to 198.211.117.129:
rsync -azP -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /root/bigfile.txt 198.211.117.129:/root/If rsync does not start make check to see if /etc/rsyncd.conf exists.
If not, nano /etc/rsyncd.conf:
Global settings
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
port = 873