Created
August 23, 2014 03:32
-
-
Save skplunkerin/ff7622ff0812c5d42f73 to your computer and use it in GitHub Desktop.
auto-start ssh-agent on login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############ FROM http://rocksolidwebdesign.com/notes-and-fixes/ubuntu-server-ssh-agent/ ########### | |
# Check to see if SSH Agent is already running | |
agent_pid="$(ps -ef | grep "ssh-agent" | grep -v "grep" | awk '{print($2)}')" | |
# If the agent is not running (pid is zero length string) | |
if [[ -z "$agent_pid" ]]; then | |
# Start up SSH Agent | |
# this seems to be the proper method as opposed to `exec ssh-agent bash` | |
eval "$(ssh-agent)" | |
# If the agent is running (pid is non zero) | |
else | |
# Connect to the currently running ssh-agent | |
agent_ppid="$(($agent_pid - 1))" | |
# and the actual auth socket file name is simply numerically one less than | |
# the actual process id, regardless of what `ps -ef` reports as the ppid | |
agent_sock="$(find /tmp -path "*ssh*" -type s -iname "agent.$agent_ppid")" | |
echo "Agent pid $agent_pid" | |
export SSH_AGENT_PID="$agent_pid" | |
echo "Agent sock $agent_sock" | |
export SSH_AUTH_SOCK="$agent_sock" | |
fi | |
################ END SSH AGENT SCRIPT ################# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my case, the
ppid
is not thepid
minus one, but theppid
can be obtained in the same manner as thepid
is found except getting the third element instead of the second.