Skip to content

Instantly share code, notes, and snippets.

@atrakeur
Created December 12, 2018 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atrakeur/d8c61f6c845b560716dc0ccd76b6f79a to your computer and use it in GitHub Desktop.
Save atrakeur/d8c61f6c845b560716dc0ccd76b6f79a to your computer and use it in GitHub Desktop.
Auto load ssh key for all prompts on first prompt open. Also ask passphrase on first load
echo "Loading ssh file"
# Ssh-agent Settings
KEY=~/.ssh/id_rsa
SSHAGENT=/usr/bin/ssh-agent
export SSH_AGENT_PID=$(pgrep ssh-agent | head -1)
SSH_AUTH_SOCK=$(ls -1 /tmp/ssh-*/* 2>/dev/null | head -n 1 )
if [[ $(pgrep ssh-agent) == "" ]]; then
rm -r /tmp/ssh-* &> /dev/null;
eval $($SSHAGENT -s)
ssh-add ${KEY}
echo "Loading private ssh key"
else
export SSH_AUTH_SOCK=${SSH_AUTH_SOCK}
export SSH_AGENT_PID=$(ps -f|grep ssh-agent|head -1|awk '{print $2}')
echo "Private ssh key loaded from another prompt, reusing"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment