From 170671f655492fa511d0f32f34be11fea8174420 Mon Sep 17 00:00:00 2001 From: Stuart Stent Date: Wed, 19 Aug 2020 08:36:16 -0400 Subject: [PATCH] added sshkey fix --- .bashrc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.bashrc b/.bashrc index a833146..d795b46 100644 --- a/.bashrc +++ b/.bashrc @@ -129,3 +129,22 @@ if [ -f '/home/sstent/google-cloud-sdk/path.bash.inc' ]; then . '/home/sstent/go # The next line enables shell command completion for gcloud. if [ -f '/home/sstent/google-cloud-sdk/completion.bash.inc' ]; then . '/home/sstent/google-cloud-sdk/completion.bash.inc'; fi alias config='/usr/bin/git --git-dir=/home/sstent/.cfg/ --work-tree=/home/sstent' + + +# 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 2>&1 + +fi