Last active
August 22, 2019 17:55
-
-
Save rfay/02474ab1787a71c47fa8ba043a894aa3 to your computer and use it in GitHub Desktop.
Starting ssh-agent just once (like on windows) wherever something isn't starting it for you
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
#!/bin/bash | |
# | |
## Auto launch of ssh-agent from | |
# https://help.github.com/articles/working-with-ssh-key-passphrases/#auto-launching-ssh-agent-on-git-for-windows | |
env=~/.ssh/agent.env | |
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; } | |
agent_start () { | |
(umask 077; ssh-agent >| "$env") | |
. "$env" >| /dev/null ; | |
} | |
agent_load_env | |
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running | |
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?) | |
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then | |
agent_start | |
fi | |
unset env | |
# Now you still have to ssh-add |
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
export PATH=~/bin:$PATH | |
. ~/.bash_sshagent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment