From time to time you want to write scripts that will allow you to copy files to or execute commands on remote systems. You want to execute these scripts without being prompted for a password and you don't want to store the password in the script file. To achieve this we can use ssh encryption keys.
Log in as root (you can use another user though):
# cd ~
# ssh-keygen -t dsa
don't add a password
# scp .ssh/id_dsa.pub root@server:/root/
Log in on the server
# mkdir .ssh
# chmod 700 .ssh
# cat id_dsa.pub >> .ssh/authorized_keys
# rm -f ~/id_dsa.pub
Log in to the client again. Use rsync to sync a directory. This copies all file in the tmp dir to the tmp dir on the remote host:
# rsync -avu –delete -e ssh /tmp/ root@server:/tmp
-u overwrite newer files on the server
-z compressed sending of the files, handy when you have a slow connection like an analoge phone line.
— delete delete files on the receiving host that don't exist on the client side.