# [solved] user cron-job with ssh-agent/keychain, pubkey error

## Seron

I've set up a user cronjob for running a script to rsync using ssh. When I run the script on the command line I don't get prompted for the key passphrase, but when executed by cron I get the following email:

```
Permission denied (publickey).

rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]

rsync error: error in rsync protocol data stream (code 12) at io.c(605) [Receiver=3.0.9]
```

What could be the reason for this?

vixie-cron-4.1-r12

openssh-5.9_p1-r4

keychain-2.7.1-r1

script:

```
#!/bin/bash

rsync --archive --update --verbose --compress --progress --rsh="ssh" --exclude='lost+found' source_srv:dir1/ /destination/dir
```

ssh connection parameters are set in ~/.ssh/config.

----------

## Seron

I got it working by adding the following to the beginning of the script:

```
eval "$(keychain --noask --eval id_dsa)" || exit 1
```

as described in the Keychain Wiki.

----------

