Skip to content

Instantly share code, notes, and snippets.

@wmakley
Created November 7, 2020 17:19
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 wmakley/69a7af4d7db5298e679187f3e87d0be9 to your computer and use it in GitHub Desktop.
Save wmakley/69a7af4d7db5298e679187f3e87d0be9 to your computer and use it in GitHub Desktop.
WSL SSH Agent Workaround
# Start ssh-agent if not started (WSL workaround)
# See: https://superuser.com/questions/1010542/how-to-make-git-not-prompt-for-passphrase-for-ssh-key-on-windows/1421619#1421619
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
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
# End ssh-agent workaround
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment