Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Extract SSH_AUTH_SOCK from SSHKeychain (OS X)

by adrianh (Chancellor)
on Feb 06, 2007 at 13:49 UTC ( [id://598538]=CUFP: print w/replies, xml ) Need Help??

I use the handy app SSHKeychain on my OS X box, which handles my SSH agent for me in various useful ways. The only problem is that the environment doesn't get set up properly for things like cron (since SSHKeychain stores it's socket info in a .plist).

This little snipped enables me to do things like:

with-sshkeychain svk sync -a 2>&1 | mail -s svk-sync-all adrianh

in my crontab and still get a connection to the SSHKeychain run ssh-agent. Super.

#! /usr/local/bin/perl # with-sshkeychain SOME OTHER COMMAND use Mac::PropertyList; my $plist = Mac::PropertyList::parse_plist_file( "$ENV{ HOME }/.MacOSX/environment.plist" ) or die "cannot parse environment.plist\n"; $ENV{ SSH_AUTH_SOCK } = $plist->value( 'SSH_AUTH_SOCK' ) or die "no SSH_AUTH_SOCK\n"; exec( @ARGV );

Replies are listed 'Best First'.
Re: Extract SSH_AUTH_SOCK from SSHKeychain (OS X)
by Fletch (Bishop) on Feb 06, 2007 at 15:30 UTC

    Of course since SSHKeychain always tends to use /tmp/$UID/SSHKeychain.socket (as long as I've been using it) one could probably safely hard code that in the crontab instead.

      Since the path is an option in the preferences, you can definitely safely hardcode it, as long as it matches what is in the preferences.


      We're not surrounded, we're in a target-rich environment!
Re: Extract SSH_AUTH_SOCK from SSHKeychain (OS X)
by Anonymous Monk on Sep 27, 2007 at 21:12 UTC
    Thanks for the comments above. The key was to set the SSH_AUTH_SOCK variable at the head of the file. I have no use for the sexy perl code, though, since I will keep this constant. I can now run cron jobs authorized with SSHKeychain using the following crontab:
    SSH_AUTH_SOCK=/tmp/501/SSHKeychain.socket 0 15 * * 1-5 /usr/bin/backup
Re: Extract SSH_AUTH_SOCK from SSHKeychain (OS X)
by jasonk (Parson) on Feb 08, 2007 at 22:40 UTC

    You could also just go into the SSHKeychain preferences and check the box that says 'Manage (and modify) global environment variables', so that it will set $SSH_AUTH_SOCK for you.


    We're not surrounded, we're in a target-rich environment!
      You could also just go into the SSHKeychain preferences and check the box that says 'Manage (and modify) global environment variables', so that it will set $SSH_AUTH_SOCK for you.

      Erm. No. The whole point is that the way that SSHKeychain manages the environment (via the  .MacOSX/environment.plist in your home directory) doesn't propagate to some things like cron which are independent of your login.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://598538]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found