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?
I know this thread is old, but for the sake of others who stumble on this problem like me, here are your two options:
For the second option, and assuming that your cron job runs with the correct user (otherwise there are more things to set correctly in your environment), just run:
env|grep -i ssh
There will be a line like:
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
The user id might be different for you. From there, you can just add the following lines to your script:
if [ -z "$SSH_AUTH_SOCK" ]
then
export SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
fi
Hope this helps!
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With