Skip to content

Instantly share code, notes, and snippets.

@matt-FFFFFF
Created August 14, 2020 14:22
Show Gist options
  • Save matt-FFFFFF/7f14dc6309c1bfcf13fe05de75917117 to your computer and use it in GitHub Desktop.
Save matt-FFFFFF/7f14dc6309c1bfcf13fe05de75917117 to your computer and use it in GitHub Desktop.
.localrc
export KEYVAULT=<<<CHANGEME>>>
# Configure ssh forwarding
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
# need `ps -ww` to get non-truncated command for matching
# use square brackets to generate a regex match for the process we want but that doesn't match the grep command running it!
ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?)
if [[ $ALREADY_RUNNING != "0" ]]; then
if [[ -S $SSH_AUTH_SOCK ]]; then
# not expecting the socket to exist as the forwarding command isn't running (http://www.tldp.org/LDP/abs/html/fto.html)
echo "removing previous socket..."
rm $SSH_AUTH_SOCK
fi
echo "Starting SSH-Agent relay..."
# setsid to force new session to keep running
# set socat to listen on $SSH_AUTH_SOCK and forward to npiperelay which then forwards to openssh-ssh-agent on windows
(setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment