Ssh – using rsync through secure ssh in a cron job

backupnetwork-attached-storagersyncssh

I am trying to set up a shell script under Debian GNU/Linux to backup a directory and subdirectories to a remote NAS running Linux over SSH. This connection has to be encrypted.

I have tried a couple different approaches involving rsync rsh and such but without luck. I know how to set up the crontab, but I need a script that will run unattended (i.e., it won't ask for password)

Could anyone help me?

EDIT:
I can successfully login without a password now.

The problem now is to get rsync to copy the files in /backups/ to [remote system]:/backups/

It only copies one folder from /backups/ to [remote system]:/backups/.

EDIT: Seems local system has one /backups and one /backup… I have tried with /backups when I should have used /backup…

Final command: rsync -avzr -e ssh /backup/ admin@[IP]:/backups/

Best Answer

rsync since 2.6.x defaults to using ssh for transfers. So it's already taken care of as long as your remote NAS rsync is supported.

As to password less unattended transfers, setup ssh key based authentication for the user you are running the cron as and that should be done. Here is how you set it up -- http://www.cyberciti.biz/tips/ssh-public-key-based-authentication-how-to.html