Skip to content

Instantly share code, notes, and snippets.

@liflovs
Created November 23, 2021 10:45
Show Gist options
  • Save liflovs/f2a950dadcca25a0dbdfe10f53f5c838 to your computer and use it in GitHub Desktop.
Save liflovs/f2a950dadcca25a0dbdfe10f53f5c838 to your computer and use it in GitHub Desktop.
Git SSH key from environmental variable
#!/usr/bin/env bash
# Init .ssh dir and expand $SSH_KEY
mkdir -p ~/.ssh
echo -e "${SSH_KEY//_/\\n}" > ~/.ssh/id_rsa
chmod og-rwx ~/.ssh/id_rsa
# Uncomment to debug
# ls -la ~/.ssh
# cat ~/.ssh/id_rsa
# Add host keys, comment out if not needed
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
ssh-keyscan -H bitbucket.org >> ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment