Skip to content

Instantly share code, notes, and snippets.

@webyneter
Created August 6, 2018 18:34
Show Gist options
  • Save webyneter/a727ef1c00ccddfb52b34a100f6f78a4 to your computer and use it in GitHub Desktop.
Save webyneter/a727ef1c00ccddfb52b34a100f6f78a4 to your computer and use it in GitHub Desktop.
SSH from GitLab CI runner
#!/usr/bin/env bash
### Source:
### https://gist.github.com/yannhowe/5ab1501156bd84c8ac261e2c17b8e3e0#gistcomment-2564991
mkdir -p ~/.ssh
# https://docs.gitlab.com/ee/ci/ssh_keys/#how-it-works
echo "${CI_RUNNER_SSH_PRIVATE_KEY}" | tr -d '\r' > ~/.ssh/id_rsa
chmod 700 ~/.ssh/id_rsa
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
# https://docs.gitlab.com/ee/ci/ssh_keys/#verifying-the-ssh-host-keys
ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment