# # the script is intended to be sourced from .bashrc # # it will start a new ssh-agent when you log in or connect you to the one # already running. mind you if there are other ssh-agent(s) running for the # current user with variables stored elsewhere than .ssh/vars.sh this script # will do nothing to regain or remove them. # # original script found at http://www.nyetwork.org/wiki/SSH # and as the author there says, it will not produce any output thus letting # things like scp or rsync run smoothly # latest version can be found here: http://genja.org/whatever/shellscripts/agent-ssh # # --jaroslav, genja.org # # # # # rxvt rxvt-unicode woot # # leave unset if you wish to run ssh-add manually ASK4PASS=yes #Time format examples: # # 600 600 seconds (10 minutes) # 10m 10 minutes # 1h30m 1 hour 30 minutes (90 minutes) SSH_AGENT_LIFE="-t 90m" SSH_VARS=$HOME/.ssh/vars.sh # everything below this line should work without intervention # # # this ps line works with: # Linux procps version 3.2.7 http://procps.sourceforge.net/ # other *nixes will need different ps arguments # TODO make a case `uname` in Linux)PSARGS=lol;; *BSD)PSARGS=blol;; Darwin)PSARGS=dlol;; esac case `uname` in Linux) psA='-a -o pid,args -p';; AIX) psA='-a -o pid,args -p';; SunOS) psA='dunno...';; *BSD) psA='axwwo pid,args';; Darwin) psA='dunno..';; CYGWIN_NT-5.1) psA='-e -f -a -p';; esac # source the variables file and find out wether ssh-agent is # still running # [ -s $SSH_VARS ] && . $SSH_VARS >/dev/null && \ RUNNING=`ps $psA $SSH_AGENT_PID |grep [s]sh-agent` # # do we have an agent? # # if [ "$SSH_AUTH_SOCK" == "" ] || [ ! -e "$SSH_AUTH_SOCK" ]\ || [ ! -S "$SSH_AUTH_SOCK" ] || [ "$RUNNING" == "" ]; then VAR=`ssh-agent 2>/dev/null` eval $VAR >/dev/null echo $VAR > $SSH_VARS fi # ask for pass-phrase on interactive shells NOID="The agent has no identities." if [ $ASK4PASS ]; then case "$-" in *i*) [ "$NOID" = "`ssh-add -l `" ] && ssh-add $SSH_AGENT_LIFE ;; *) ## stay quiet ;; esac fi