Created
July 6, 2017 12:30
-
-
Save romuloceccon/8c0a4e3bad64a4476a0f23cdff3dd019 to your computer and use it in GitHub Desktop.
Small script to start an ssh-agent instance or initialize session with variables from an existing one (put at the end of your .bashrc)
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
| SSH_FILE=$HOME/.ssh-agent-data | |
| if [[ -z "$SSH_AUTH_SOCK" ]] | |
| then | |
| [[ -f "$SSH_FILE" ]] && SSH_VARS=($(cat $SSH_FILE)) || SSH_VARS=() | |
| if [[ -z "${SSH_VARS[@]}" || ! -S "${SSH_VARS[0]}" ]] | |
| then | |
| eval "$(ssh-agent)" | |
| echo $SSH_AUTH_SOCK $SSH_AGENT_PID> $SSH_FILE | |
| else | |
| export SSH_AUTH_SOCK=${SSH_VARS[0]} | |
| export SSH_AGENT_PID=${SSH_VARS[1]} | |
| echo "Agent pid $SSH_AGENT_PID (found)" | |
| fi | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment