# This script is intended to be sourced from .bashrc # # It will start a new ssh-agent when you log in. # If you forward an agent, than that will be used. # If the one you started last time has an identity, nothing happens. # # It will do nothing to existing apents and only try to interact # with the one identified by variables in .ssh/vars.sh this script # # original script: http://www.nyetwork.org/wiki/SSH # latest version: # https://raw.githubusercontent.com/tox2ik/agent-ssh/master/.agent-ssh # # --jaroslav, genja.org # # ASK4PASS=${ASK4PASS:-yes} # Time format examples: # 600 600 seconds # 10m 10 minutes # 1h30m 1 hour 30 minutes SSH_AGENT_LIFE="-t 7d" SSH_VARS=$HOME/.ssh/vars.sh ssh-add -l &>/dev/null; # list identities from forwarded agent ADD=$? not_running=1 forwarded_empty=2 if ( [ $ADD -eq $forwarded_empty ] || [ $ADD -eq $not_running ] ) && [ -s $SSH_VARS ]; then # there is no agent, but we have a file with ssh-add output echo "source $SSH_VARS &>/dev/null" source $SSH_VARS &>/dev/null fi if ! ssh-add -l &>/dev/null; then # nothing forwarded, nothing started/added; run a new agent. ssh-agent > $SSH_VARS 2>/dev/null source $SSH_VARS &>/dev/null fi if [ $ASK4PASS ]; then case "$-" in # ask for pass-phrase on interactive shells *i*) [ "The agent has no identities." = "`ssh-add -l `" ] && ssh-add $SSH_AGENT_LIFE ;; *) ## stay quiet on non-interactive shells esac fi