SSH public key authentication problem with cron
I've got an interesting problem I was hoping someone has come across before. I'm running RHEL 5.2 boxes and am trying to scp files from a client to a server using a cron job. I've set up public key authentication and that works fine when I run my scp command from the command line as root (script is owned by root for now, until I figure the problem out).
I've set up ssh-agent and the private key passphrase is being saved in session, so when the scp command is run from the command line I am able to send the file to the server without being prompted for the private key passphrase or the account password. Everything works good. BUT...
when run as a cronjob, the server doesn't accept the authentication and the transfer fails. I've set up DEBUG2 logging on the server and it shows that the public key authentication occured, but then shows that public key authentication was "postponed". Immediately after that, password authentication is invoked (which obviously fails). I should also note that I'm throwing scp the -o PreferredAuthentications=publickey option in order to tell the server to use pk authentication first.
I figured it could be a problem with the .ssh id_rsa file of the user on the client, but my permissions are 600 on the directory ~/.ssh and the private key file, which should be right. I also made sure to set up root's own crontab file (crontab-e while logged in as root) to schedule the transfer (and I've also made sure to permit root login in the sshd_config file on the server).
Can't figure out what is wrong, but I'm guessing it has something to do with the cronjob not being able to access the private key file on the client. I added an echo | ssh-add -l line to the script I'm trying to run and it wasn't able to open the authentication information (although again, when I run ssh-add -l from the command line it displays the id's being stored correctly).
Thanks for any suggestions you all might have. Sorry- can't post the log files as they're in my office and I'm at home right now.
Last edited by pbjason9; 03-20-2009 at 12:22 AM.