4

I am trying to set up a cron to run this command:

rsync -e "ssh -i /home/ldsmp3/ssh-key -o GSSAPIAuthentication=no" -az /home/ldsmp3/public_html [email protected]:remote-dir%%bak-ldsmp3.com%%myid%%mykey

When I run the above command in terminal, it works just fine. However, when I run that same command through cron, it fails and sends me an email that contains the following...

Host key verification failed.
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(463) [sender=2.6.8]

I've been searching online for hours now trying to figure out how to fix the problem, but nothing I've tried so far has worked.

Any ideas on how to get this command to work properly through cron?

Thanks!

EDIT: Oh and I'm trying to run this command on my dedicated server running Centos 5.5

2
  • what happens if you have the cron entry be echo rsync ... Feb 5, 2011 at 1:31
  • 1
    This isn't an rsync problem, it's an ssh problem. Reduce the complexity of the command. First, move the ssh-key to .ssh/id_rsa or .ssh/id_dsa, depending on which type of key it is. Then show us the output of "ssh -v [email protected]". Once that works, move on to rsync.
    – Alex Holst
    Feb 5, 2011 at 2:39

3 Answers 3

4

The first part of the error is what you probably need to be looking at.

Host key verification failed

Is the remote hosts key added to the appropriate .ssh/known_hosts file? Has the host key changed recently? Does the account you are running rsync/ssh from have access to the appropriate known_hosts file?

2
  • I added the remote hosts key to the appropriate .ssh/known_hosts file for the user that is running the cron job, but now I'm getting this error message when the cron executes...
    – lewisqic
    Feb 5, 2011 at 1:56
  • Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-with-mic,password).
    – lewisqic
    Feb 5, 2011 at 1:56
1

cron eats percent signs. Either put your rsync command into a script called from cron, or escape your percent signs by doubling them.

12
  • Thanks, but I changed my command and escaped all of the percent signs but I'm still receiving the exact same error.
    – lewisqic
    Feb 5, 2011 at 0:53
  • Are you running it in your user crontab or in the root crontab? I suggest as a next step to put your command in a script that gets called my cron. Then turn up debugging in ssh with -vvv and capture the output to a logfile. Feb 5, 2011 at 1:00
  • I'm running it in my user crontab. Should I run it in the root crontab?
    – lewisqic
    Feb 5, 2011 at 1:02
  • Would you mind explaining how I can capture the output to a logfile?
    – lewisqic
    Feb 5, 2011 at 1:03
  • 2
    debug1: read_passphrase: can't open /dev/tty: No such device or address - when you run on cmd line, you have key loaded into memory. In cron, you don't and ssh wants to ask for the passphrase, but can't because you don't have a tty. Feb 5, 2011 at 2:51
0

What user is cron running your rsync job from? Is it the same one that you're running from the command line? If not, your .ssh/known_hosts file will be different and I'd expect to see that error.

1
  • "ldsmp3" is the user that is running the cron. No, it is not the same user as when I run the command line, I use root when I run the command line. What do I have to do with the known_hosts file to make it work so "ldsmp3" can run the cron? Thank you for your help.
    – lewisqic
    Feb 5, 2011 at 1:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .