Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Cron job not running - script uses rsync, ssh (with id_rsa)

Does anyone know how to get cron to run a rsync/ssh script which uses id_rsa for passwordless logins?


I have a backup script I have slaved for months over that works wonderfully when running it from the command line.


It uses rsync and connects with SSH (passwordless using ssh keys). I have setup id_rsa and id_rsa.pub for passwordless logins (this is my user account, and connects using root@ to the server)


As stated all works find when run from the command line. But when I setup a cron job to run this file (exact same line I run from the command line) it does not execute. Actually, it does run, as I have an email notifiction which sends to me. It is just the rsync/ssh part that does not run.


I have spent days and days trying to figure it out. No error messages occur, nothing. Took me a while to find out cron is emailing the user account on Lion the messages (not to a proper email address).


The error shows a permission denied, which I believe to be the cron user cannot use the id_rsa/ssh connection.


Cron is running the script as my user, the same I use on the command line. I even tried copying the id_rsa to the root user .ssh folder in case cron is running as root but that does not work either.



So does anyone know how to get cron to run this rsync/ssh script which used id_rsa for passwordless logins?


Thanks a lot

iMac, Mac OS X (10.7.3)

Posted on Apr 26, 2012 9:05 AM

Reply
21 replies

Jun 6, 2012 1:16 AM in response to amityweb

Using Lingon results in the keychain password dialogue when it runs, to access the SSH Key password. So as this is run overnight this does not work.


I am still amazed a Mac cannot run cron/launchd jobs that require SSH using password protected keys. The only solution is to remove the password in my keys which is far less secure.

Jun 24, 2012 3:21 AM in response to amityweb

I am setting up an Ubuntu Server Box, 12.04 Pangolin, (from now on USB) onto my old PC.

I just have one admin user, no root enable, and sshd to remote login.


I generated and tested a key pair to passwordless login from iMac to USB.


On my iMac, Lion 10.7.4, using my standard user, I scheduled a standard crontab that read like this


# m h dom mon dow command

00 12 * * * ~/bin/testsh


this is the contents of testsh


#!/bin/bash


rsync -e ssh -avz ~/testfile.zip admin@192.168.1.200:~


The script runs flawlessly at noon. No error at all. I got testfile.zip transferred from iMac to USB


Jun 24, 2012 5:21 AM in response to Alberto Ravasio

You mention "passwordless login" though. This will work fine. But its also less secure. No way I am having a passwordless key pair setup for my servers. My issue is when using a password.


When the script runs it just will not use the password stored in Keychain. It keeps asking for the password, and asking to store it in keychain, but never uses it next time, and keeps asking for it every day.


So basicaly a Mac cannot be used for automated rsync backups unless you use passwordless keys.

Jun 25, 2012 1:37 AM in response to Linc Davis

Ok will try that thanks... the find line just outputs "/tmp/launch-SUCEmE/Listener", so couldn't I just use:

SSH_AUTH_SOCK=$(
/tmp/launch-SUCEmE/Listener)


What I have been using is an app called keychain (not the Mac Keychain). http://www.funtoo.org/wiki/Keychain


Without this I would not even get the password pop up, it would fail with permission errors. So it got me closer. Lets see whay happsns with this ssh_auth_sock. Have to wait until this evening though, because it all works when I am on the computer in the day... its when I lock the screen and go home it fails... the password box is always there when I come in in the morninng.


Thanks

Cron job not running - script uses rsync, ssh (with id_rsa)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.