Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having troubles getting an rsync script to work on cron. I know this is a question that's been asked aplenty, but I've read all the answers I can find, and followed all of the instructions, but nothing seems to work for me; I'm probably missing something simple.

I have a script that more or less does this:

/usr/bin/rsync -av -e "/usr/bin/ssh -o StrictHostKeyChecking=no -i /root/.ssh/id_dsa" /data/ root@myoffsiteserver.com:/backup/last/data/

The script works just fine when I run it manually from ssh as root (key authentication works as expected, and it does not ask for a password), but doesn't seem to want to connect when running through cron as root.

The error log is filled with:

Permission denied, please try again.
Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(605) [sender=3.0.9]

Any thoughts?

share|improve this question
2  
Is your private key encrypted? I would think so... so you would have to provide a password. Perhaps on console you have cached it in your SSH-agend!? –  cljk Oct 24 '12 at 6:51
1  
Try adding some "-v" switches to the ssh command, so you can see what ssh does. Maybe the output contains clues about why ssh doesn't use you key. –  Lacek Oct 24 '12 at 6:58
    
Thanks. I unencrypted the id_rsa key and it works now. Is there any way to keep the key encrypted and get this to work? Or is that just not possible? –  Talik Oct 24 '12 at 18:29
    
@Talik, depending on how the cronjob is configured, the command could be executing as a different user or that it is running under a sub-shell which would be causing interference. –  bmurtagh Oct 26 '12 at 18:46
    
Show us the cron entry –  jwbensley Jan 30 '13 at 9:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.