Skip to content

Instantly share code, notes, and snippets.

@Varstahl
Created March 10, 2023 11:43
Show Gist options
  • Save Varstahl/8b3b92539b8391fb35499dfa9ee4da6d to your computer and use it in GitHub Desktop.
Save Varstahl/8b3b92539b8391fb35499dfa9ee4da6d to your computer and use it in GitHub Desktop.
Use SSH agent on WSL2 and add OpenSSH keys from the host. We pipe private keys instead of using the files directly because of loose permissions on the host filesystem.
# Activate ssh agent
if [ -z "${SSH_AUTH_SOCK}" ]; then
eval $(ssh-agent -s)
fi
# SSH keys
keys=( $(ssh-add -l | awk '{print $2}') )
if [[ ! ${keys[*]} =~ (^|[[:space:]])"SHA256:…"([[:space:]]|$) ]]; then
echo XYZ key absent, adding it…
ssh-add - < /mnt/…/private_key.pem
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment