Last active
June 12, 2023 16:24
-
-
Save KairuDeibisu/73b248462cb37de09bf2e4c1d73c4389 to your computer and use it in GitHub Desktop.
Forward SSH from WSL 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configure ssh forwarding | |
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock | |
# Use pgrep to check if the process is running | |
pgrep -f "npiperelay -ei -s //./pipe/openssh-ssh-agent" > /dev/null | |
IS_ALREADY_RUNNING=$? | |
if [[ $IS_ALREADY_RUNNING -ne 0 ]]; then | |
if [[ -S $SSH_AUTH_SOCK ]]; then | |
# Not expecting the socket to exist as the forwarding command isn't running | |
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 -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment