# kshrc code to invoke or point to running ssh-agent # This code is in the public domain. It was written by J.D. Baldwin # in August, 2002. It is not warranted for any purpose whatever, and # as with any code, you should examine it carefully to determine # whether it meets your needs before running it on your own machine. # I would appreciate it if you would leave my name attached to this # code wherever you use or redistribute it; that way, if someone finds # a problem with it, I can be notified. # The idea behind this code is that it comes at the end of your .kshrc # (or equivalent) file. It is wrapped by a conditional to determine # whether you really want ssh-agent running on the host to which you # are logging in. (It's unlikely that you want the agent running # everywhere you go.) Change the value of AGENT_HOSTS to reflect your # environment. Everything else should work without changes, assuming # all of the programs are in your PATH. # The basic idea is that the output of ssh-agent is captured on first # invocation and placed in /tmp/env_ssh.$LOGNAME. On subsequent shell # invocations, because that file exists, its contents are sourced into # the new shell. # At the end are some aliases to aid you in managing the key cache. # You should *strongly* consider using a timeout value (with the -t # option) on your caching. It isn't in here because Solaris 9's # ssh-agent doesn't support timeouts. @#$%! export HOSTNAME=$(/bin/uname -n) export AGENT_HOSTS='admin1 admin2 personal_box' # If host is in AGENT_HOSTS ... print $AGENT_HOSTS | grep -iw $HOSTNAME >/dev/null 2>&1 if [[ $? -eq 0 ]] # if current hostname is found ... then # ... then detect / set up / run the ssh-agent unset SSH_AUTH_SOCK; unset SSH_AGENT_PID; pgrep ssh-agent >/dev/null 2>&1 if [[ $? -ne 0 ]] then print -n 'ssh-agent being started ... ' ssh-agent > /tmp/env_ssh.$LOGNAME print 'done.' . /tmp/env_ssh.$LOGNAME elif [[ ! -f /tmp/env_ssh.$LOGNAME ]] then print WARNING: ssh-agent process exists with no /tmp/env_ssh.$LOGNAME file print -n 'ssh-agent being killed and restarted ... ' pkill ssh-agent ssh-agent > /tmp/env_ssh.$LOGNAME print 'done.' . /tmp/env_ssh.$LOGNAME else print 'ssh-agent already running ... loading environment' . /tmp/env_ssh.$LOGNAME fi # And here are some aliases you may find useful: # # skeya - add DSA identity file to cache # skeyl - list identity or identities in cache # skeyd - delete all identities from cache # skeyk - kill the agent alias skeya='ssh-add ~/.ssh/id_dsa' alias skeyl='ssh-add -l' alias skeyd='ssh-add -D' alias skeyk='eval $(ssh-agent -k) ; /bin/rm -f /tmp/env_ssh.$LOGNAME' fi