Search code examples
bashsshcronrsync

Using cron with ssh keys


I am using a cron script that rsyncs with a server via ssh.

The commands work great when I run them directly as a bash script, but when I run them as cron, cron logs out bad permissions. I think this is because the cron user does not have access to the ssh key.

This is the code that I need cron to run:

rsync --progress -rvze ssh my_user@myserver/root_folder folder/

Can I pass the ssh key into the cronfile, or into the script itself? If so, would you provide an example like the one above?


Solution

  • add '-i' switch to your ssh command in your command line:

    rsync --progress -rvze "ssh -i/path/to/ssh_private_key" my_user@myserver:/root_folder folder/