Skip to content

Instantly share code, notes, and snippets.

@Machy8
Created August 26, 2019 21:21
Show Gist options
  • Save Machy8/c9e85a8574ec6b0956edf091f82d4183 to your computer and use it in GitHub Desktop.
Save Machy8/c9e85a8574ec6b0956edf091f82d4183 to your computer and use it in GitHub Desktop.
  1. Generate ssh key (if not exists)
  • No passowrd or anything
ssh-keygen
  1. Create variable with SSH_PRIVATE_KEY and add the ~/.ssh/id_rsa private key into it
  2. Add the key into authorized keys cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  3. Create init section in .gitlab-ci.yml
before_script:
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  1. Connect and run command in one connection
ssh username@address  "git fetch --all; git reset --hard origin/master; git pull origin master; ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment