-
Notifications
You must be signed in to change notification settings - Fork 1
/
sagent.mac
executable file
·30 lines (24 loc) · 983 Bytes
/
sagent.mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# SAGENT starts an SSH agent if my user doesn't already have one running.
# It first looks up ssh-agent processes associated with my user and sets
# the environment variable associated with it so the terminal recognizes it.
# If it doesn't find on, it starts one.
# This script gets sourced in my bashrc/zshrc.
# The difference between this and the linux version is that
# for some reason, ssh-agent ignores `-a` (bind address) on OSX.
# Therefore we don't set the bind address manually.
# And the time limit is longer.
AGENTFOUND=0
for agentsocket in $(pgrep -f -n -u $(whoami) "ssh-agent -s") ; do
AGENTFOUND=1
export SSH_AGENT_PID=$agentsocket
break
done
# If at this point we still haven't located an agent, it's time to
# start a new one
if [ $AGENTFOUND = 0 ] ; then
eval "$(ssh-agent -s -a ~/.ssh/ssh-agent.sock -t 18h)"
export SSH_AGENT_PID=$SSH_AGENT_PID
fi
export SSH_AUTH_SOCK=~/.ssh/ssh-agent.sock
echo "Agent set: ${SSH_AGENT_PID}"