Skip to content

Instantly share code, notes, and snippets.

@stuartleeks
Last active May 4, 2020 20:47
Show Gist options
  • Select an option

  • Save stuartleeks/43111bfb76b5bc48b6e15377fbc4848e to your computer and use it in GitHub Desktop.

Select an option

Save stuartleeks/43111bfb76b5bc48b6e15377fbc4848e to your computer and use it in GitHub Desktop.

Revisions

  1. stuartleeks revised this gist May 4, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions .bashrc-ssh-forward.sh
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,11 @@ export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
    # 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
  2. stuartleeks revised this gist May 2, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .bashrc-ssh-forward.sh
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    # Ensure that the ssh-agent service is running on windows
    # build https://github.com/jstarks/npiperelay and ensure it is in your PATH (or modify the script to specify the qualified path)

    # Confi
    # 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!
  3. stuartleeks created this gist May 2, 2020.
    19 changes: 19 additions & 0 deletions .bashrc-ssh-forward.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #
    # Set up ssh agent forwarding to host
    #

    # Include this in .bashrc
    # Ensure that the ssh-agent service is running on windows
    # build https://github.com/jstarks/npiperelay and ensure it is in your PATH (or modify the script to specify the qualified path)

    # Confi
    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
    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 &) 2>&1 > /dev/null
    fi