Rsync with ssh keys
From Wsms
If you have a shell account with on more than one linux host, rsync with ssh keys is a very efficient way to keep directories synchronized. The ssh keys allow you to run rsync without typing in your remote password. Thus, you can even run rsync as part of a cron job.
Suppose that I have an account for ggeller an a machine called arthur (my local machine) and a second account mckinley (a remote server). I'm working on some perl scripts in /home/ggeller/Desktop/pl and I want to back them up to mckinley. Here's how:
[ggeller@arthur ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/ggeller/.ssh/id_rsa): Created directory '/home/ggeller/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ggeller/.ssh/id_rsa. Your public key has been saved in /home/ggeller/.ssh/id_rsa.pub. The key fingerprint is: c8:86:c6:cf:56:f9:0c:09:c1:4a:9a:5e:75:a5:e3:6c ggeller@arthur.sdlinuxguy.com [ggeller@arthur ~]$ scp .ssh/id_rsa.pub mckinley: The authenticity of host 'mckinley (192.168.2.14)' can't be established. RSA key fingerprint is 2b:ae:db:b9:5d:f2:d3:50:e8:fe:2b:fc:bc:87:f5:19. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'mckinley,192.168.2.14' (RSA) to the list of known h\osts. ggeller@mckinley's password: id_rsa.pub 100% 411 0.4KB/s 00:00 [ggeller@arthur ~]$ ssh mckinley ggeller@mckinley's password: Last login: Thu Dec 21 20:57:02 2006 from arthur [ggeller@mckinley ~]$ mkdir .ssh [ggeller@mckinley ~]$ chmod 700 .ssh [ggeller@mckinley ~]$ mv id_rsa.pub .ssh/authorized_keys2 [ggeller@mckinley ~]$ chmod 600 .ssh/authorized_keys2 [ggeller@mckinley ~]$ logout Connection to mckinley closed. [ggeller@arthur ~]$ cd Desktop [ggeller@arthur Desktop]$ rsync -av pl mckinley: building file list ... done pl/ pl/IP-eth0.pl pl/IP-eth0.pl~ sent 1386 bytes received 70 bytes 970.67 bytes/sec total size is 1173 speedup is 0.81
[edit]
