Created
March 10, 2023 11:43
-
-
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.
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
# 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