
Instruction that I followed: https://stuartleeks.com/posts/wsl-ssh-key-forward-to-windows/ Using this tool to make Windows named pipes available in WSL: https://github.com/jstarks/npiperelay
49 lines
1 KiB
Bash
49 lines
1 KiB
Bash
#!/bin/sh
|
|
usage () {
|
|
echo "usage: $0 [-w] [-h]"
|
|
echo " -w use the WSL ssh-agent instead of OpenSSH for Windows"
|
|
echo " -h show help and exit"
|
|
}
|
|
|
|
# Use OpenSSH for Windows by default.
|
|
WSL_SSH_AGENT=false
|
|
|
|
while getopts ":wh" arg; do
|
|
case "$arg" in
|
|
w)
|
|
WSL_SSH_AGENT=true
|
|
;;
|
|
|
|
h)
|
|
>&2 usage
|
|
exit 0
|
|
;;
|
|
|
|
?)
|
|
>&2 echo "ERROR: unknown option -$OPTARG"
|
|
>&2 usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ "$WSL_SSH_AGENT" = true ]; then
|
|
exec ssh-agent tmux new-session -A -t main "$@"
|
|
fi
|
|
|
|
require() {
|
|
if ! command -v "$@" >/dev/null 2>&1; then
|
|
>&2 echo "ERROR: required command not found: $1"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
require socat
|
|
require npiperelay
|
|
|
|
# Forward SSH Agent requests from withitn WSL to OpenSSH for Windows, based on:
|
|
# https://stuartleeks.com/posts/wsl-ssh-key-forward-to-windows/
|
|
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
|
|
socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay -ei -s //./pipe/openssh-ssh-agent",nofork &
|
|
exec tmux new-session -A -t main "$@"
|
|
|