You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

where is SSH_AUTH_SOCK set?

Hello,

I recently set up non-interactive ssh login from my machine (running Leopard) to a remote server using ssh keys and ssh-agent, but I'm not particularly happy with the solution. What I've had to do is explicitly set the SSH AUTHSOCK environment variable in a script launched by a cron job like this:

<pre>
export SSH AUTHSOCK=$(/usr/sbin/lsof | grep Listeners | grep ssh-agent | awk '{print $8}')
ssh -l someuser somehost.with.my.public.key "some command"
</pre>

As long as I've added the relevant private key for someuser using ssh-add since startup, unprompted login succeeds. I've noticed that if I log into my machine as someuser (ie, sitting in front of it), the SSH AUTHSOCK variable is set (even if I log out and log back in), but if I ssh in or run a cron job, it is not, and I have to set the variable explicitly as above.

Is there a more elegant solution than what I've done here? I'd rather configure non-interactive sessions so that I don't need to explicitly set SSH AUTHSOCK, but I can't figure out where in the logon process this variable is defined (someuser uses bash, but I'd like to be able to generalize to other shells). I'd also like to come up with a less fragile-seeming method of locating the "Listeners" socket file.

Thanks,
Noah

Mac OS X (10.5.4)

Posted on Aug 21, 2008 10:53 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 23, 2008 6:03 PM

In Leopard, SSH AUTHSOCK is set by launchd and inherited by any login process you start, but not by a LaunchAgent or cron job. This is faster than running lsof:

<pre>SSH AUTHSOCK=$( ls /tmp/launch-*/Listeners )</pre>

It may not work if the ssh job runs as root.
1 reply

where is SSH_AUTH_SOCK set?

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