From 470ae38f1ce542e7d30c732ba20ae2042f183391 Mon Sep 17 00:00:00 2001 From: Scott Carroll Date: Sun, 18 May 2025 20:49:14 +0100 Subject: [PATCH] Add local bashrc to fetch ssh keys from 1Password --- bashprofile/bashrc-local-homessh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 bashprofile/bashrc-local-homessh diff --git a/bashprofile/bashrc-local-homessh b/bashprofile/bashrc-local-homessh new file mode 100644 index 0000000..479d5ba --- /dev/null +++ b/bashprofile/bashrc-local-homessh @@ -0,0 +1,21 @@ +# Code extracted from https://stuartleeks.com/posts/wsl-ssh-key-forward-to-windows/ with minor modifications + +mkdir -p /home/scottc/.1password + +# Configure ssh forwarding +export SSH_AUTH_SOCK=$HOME/.1password/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 +