Re: [dev] ssh-agent stanza in POSIX shell

From: Eckehard Berns <ecki-suckless_AT_ecki.to>
Date: Sun, 30 Oct 2011 21:16:15 +0100

> I've found the following clever ssh-agent stanza in Richard Crowley's
> `.profile`[https://raw.github.com/rcrowley/home/master/.profile]:
>
> which ssh-agent >/dev/null && {
> : ${SSH_AUTH_SOCK:=$(echo /tmp/ssh-*/agent.* | cut -d" " -f1)}
> [ -S "$SSH_AUTH_SOCK" ] && {
> export SSH_AUTH_SOCK
> } || {
> eval $(ssh-agent)
> ssh-add
> }
> }
>
> Wondering why it doesn't work properly in OpenBSD ksh as I am not so
> good with POSIX sh.

Can't really tell which part doesn't work in OpenBSD ksh (I got used to
mksh and it got a lot of bashism lately). Anyway, I personally would
rather write it like this (not tested, I personally use
~/.ssh-agent-info to store ssh-agent's socket and PID):

if which ssh-agent >/dev/null
then
        test -z "$SSH_AUTH_SOCK" && \
                SSH_AUTH_SOCK=`echo /tmp/ssh-*/agent.* | cut -d\ -f1`
        if test -S "$SSH_AUTH_SOCK"
        then
                export SSH_AUTH_SOCK
        else
                eval `ssh-agent`
                ssh-add
        fi
fi

Hmm, just glanced over OpenBSD's manual for ksh and it seems all
constructs used are supported by OpenBSD's ksh - so the original code
should work there too... strange... or is TMPDIR set to something other
then /tmp? Does ssh-agent place its socket into /tmp/ssh-*/agent.*? (The
manual only states the socket lives in $TMPDIR/ssh-*/agent._ppid_.)

-- 
Eckehard Berns
Received on Sun Oct 30 2011 - 21:16:15 CET

This archive was generated by hypermail 2.3.0 : Sun Oct 30 2011 - 21:24:05 CET