Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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?


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

share|improve this question
what happens if you have the cron entry be echo rsync ... – becomingwisest Feb 5 '11 at 1:31
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". Once that works, move on to rsync. – Alex Holst Feb 5 '11 at 2:39

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?

share|improve this answer
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 '11 at 1:56
Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-with-mic,password). – lewisqic Feb 5 '11 at 1:56

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

share|improve this answer
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 '11 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. – Phil Hollenback Feb 5 '11 at 1:00
I'm running it in my user crontab. Should I run it in the root crontab? – lewisqic Feb 5 '11 at 1:02
Would you mind explaining how I can capture the output to a logfile? – lewisqic Feb 5 '11 at 1:03
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. – Phil Hollenback Feb 5 '11 at 2:51

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.

share|improve this answer
"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 '11 at 1:45

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.