Created
December 12, 2018 10:30
-
-
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
This file contains 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
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