summaryrefslogtreecommitdiffstats
path: root/bashrc
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2021-08-17 10:49:49 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2021-08-17 10:49:49 +0200
commite3d5a59dcab323b40b836ce4f965080eca407319 (patch)
treea6917ad7fd34e248371c13d805ddd282f11ca77a /bashrc
parentce485ee9e4f85d65d9c4b35ef7fead3fe7dc4763 (diff)
downloadbin-e3d5a59dcab323b40b836ce4f965080eca407319.zip
bin-e3d5a59dcab323b40b836ce4f965080eca407319.tar.gz
bashrc : cleaner ssh-agent script
Diffstat (limited to 'bashrc')
-rw-r--r--bashrc30
1 files changed, 9 insertions, 21 deletions
diff --git a/bashrc b/bashrc
index ee1ee18..228f49c 100644
--- a/bashrc
+++ b/bashrc
@@ -134,26 +134,14 @@ function xtract() {
}
# SSH
-SSH_ENV=${HOME}/.ssh/environment
-function start_agent {
- /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
- chmod 600 ${SSH_ENV}
- . ${SSH_ENV} > /dev/null
- # /usr/bin/ssh-add $(ls ~/.ssh/*.pub | sed 's/\.pub.*//g' | tr '\n' ' ')
-}
-if [ -e "${SSH_ENV}" ]
+ssh-add -l &>/dev/null
+if [ $? -ne 0 ]
then
- . ${SSH_ENV} > /dev/null
- ps ux | grep ssh-agent$ | grep ${SSH_AGENT_PID} >/dev/null || {
- # kill old agents
- PIDS=`pidof ssh-agent`
- if [ ! -z "${PIDS}" ]; then
- for PID in ${PIDS}; do
- kill ${PID} 2>/dev/null
- done
- fi
- start_agent;
- }
-else
- start_agent
+ [ -r ~/.ssh/agent ] && eval "$(<~/.ssh/agent)" >/dev/null
+ ssh-add -l &>/dev/null
+ if [ $? -ne 0 ]
+ then
+ (umask 066; ssh-agent > ~/.ssh/agent)
+ eval "$(<~/.ssh/agent)" >/dev/null
+ fi
fi