msgbartop
Adam Palmer MBCS CITP, Linux, PHP Programmer, MySQL Developer, Embedded Hardware, Security Consultant
Did my blog help you? Please link to me!
  dns test
 
RSS Feed
msgbarbottom

24 Oct 08 rsync over SSH, SSH key login, public keys, automated backups

This tutorial will cover how to set up a simple backup job between two machines using rsync and ssh. You will need HOST A and HOST B, whereby HOST B is your target backup service.

On HOST B:

ssh-keygen -t rsa  # Press enter to accept the default options.
mv ~/.ssh/id_rsa ~/.ssh/identity
cat ~/.ssh/id_rsa.pub

This will output something like:

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtD7thPdP41CtJy/Gsxyvf/7NYdpiNPxF//HqMihw1yH9FHjnOpDd9uLMi8sYxfR/+tzGwD2dMoZn2b9tVaNOZdL+RMSctqmRMHHCjM7ENQepPU5RRtevt53qTugsSRF73bUT/KYKaJtnIzze9REb+6aVgHK+mkyoZ4uPwn6kEmIauKA/qL0hfyCVuz0ocYGRS3jAfCfW7e8oLC8az5bN9SqJE0/19p3921MzvwyvBLzg4EDbDHUMPWq+h0KjLMdILCnYbsf2HHizPdeURu61tznnj3MJKVRU5eeI8+FvOGPq2Oe9JDULrvRTtmuxIe4xslLsjcvufwBQST68KpaxYQ== user@host

Copy and paste this into ~/.ssh/authorized_keys on HOST A.

Now the following should log in without prompting for a password or user input:

ssh user@host_a

Assuming this works, great!

Now on HOST B:

rsync -azu –stats –progress user@host_a:/etc ~/backups/

The options used are explained as follows:
-a ‘archive mode’ (Keep uid,gid,permissions,etc)
-z compress transfer if possible
-u only updated files

Now in this case, HOST B connects to HOST A and pulls off the relevant data. You can just as easily run things the opposite way round, and have HOST A connect to and put it’s data onto HOST B, however assuming HOST B is your backup service, you may prefer to have the backup service go out and get the backups rather than giving other hosts a login/shell to your backup service.

Tags: , , , , , , , ,



Leave a Comment