Stop automagically reloading agents, I know use a single one and ssh -A.

This commit is contained in:
Julien Palard 2017-08-01 15:04:16 +02:00
parent 69776adbe5
commit 1f823d2a4e

62
.bashrc
View File

@ -1,36 +1,3 @@
# Try to restore environment variable of an ssh-agent
ssh-agent-restore()
{
local QUIET="$1"
local AUTH_SOCKS_AND_NAME=( )
local AGENTS="$(ls -1tr /tmp/ssh-*/* 2>/dev/null)"
if [ z"$?" != z"0" -a -z "$QUIET" ]
then
printf "No ssh-agent found.\n" 1>&2
return 1
fi
if [ -z "$QUIET" ]
then
for auth_sock in $AGENTS
do
AUTH_SOCKS_AND_NAME=( "${AUTH_SOCKS_AND_NAME[@]}" "$(printf "%s " "$auth_sock"; SSH_AUTH_SOCK="$auth_sock" ssh-add -l | cut -d' ' -f3- | tr '\n', ' ')" )
done
select AUTH_SOCKS in "${AUTH_SOCKS_AND_NAME[@]}"
do
export SSH_AUTH_SOCK="$(printf "%s" "$AUTH_SOCKS" | awk '{print $1}')"
break
done
else
export SSH_AUTH_SOCK="$(printf "%s" "$AGENTS" | tail -n 1)"
fi
export SSH_AGENT_PID="${SSH_AUTH_SOCK##/*/*.}"
}
# Do this even in non-interactive shells, this permit :
# ssh host1 ssh host2 ssh host3
# If you only have one agent running on each host, it will use it.
ssh-agent-restore --quiet
# If not running interactively, don't do anything more
[ -z "$PS1" ] && return
@ -197,3 +164,32 @@ function _workon
}
complete -F _workon workon
# Restore environment variable of existing ssh-agents
ssh-agent-restore()
{
local QUIET="$1"
local AGENTS="$(ls -1tr /tmp/ssh-*/* 2>/dev/null)"
local AUTH_SOCKS_AND_NAME=( )
if [ z"$?" != z"0" -a -z "$QUIET" ]
then
printf "No ssh-agent found.\n" 1>&2
return 1
fi
if [ -z "$QUIET" ]
then
for auth_sock in $AGENTS
do
AUTH_SOCKS_AND_NAME=( "${AUTH_SOCKS_AND_NAME[@]}" "$(printf "%s " "$auth_sock"; SSH_AUTH_SOCK="$auth_sock" ssh-add -l | cut -d' ' -f3- | tr '\n', ' ')" )
done
select AUTH_SOCKS in "${AUTH_SOCKS_AND_NAME[@]}"
do
export SSH_AUTH_SOCK="$(printf "%s" "$AUTH_SOCKS" | awk '{print $1}')"
break
done
else
export SSH_AUTH_SOCK="$(printf "%s" "$AGENTS" | tail -n 1)"
fi
export SSH_AGENT_PID="${SSH_AUTH_SOCK##/*/*.}"
}