Skip to content

Instantly share code, notes, and snippets.

@kas-cor
Last active June 4, 2020 14:36
Show Gist options
  • Save kas-cor/316a486eae32298f20524351d5e83e5d to your computer and use it in GitHub Desktop.
Save kas-cor/316a486eae32298f20524351d5e83e5d to your computer and use it in GitHub Desktop.
My gitlab CI for SSH Exes deploy
image: jimmyadaro/gitlab-ci-cd:latest
before_script:
- mkdir -p ~/.ssh
- echo "$PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 700 ~/.ssh
- chmod 600 ~/.ssh/id_rsa
- eval $(ssh-agent -s)
- ssh-add ~/.ssh/id_rsa
Deploy:
stage: deploy
only:
- master
script:
- cat ./deploy.sh | ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa -p $SERVER_PORT $SERVER_USER@$SERVER_HOST
@kas-cor
Copy link
Author

kas-cor commented Aug 1, 2019

Use

In GitLab.com

Goes to settings > CI / CD > Variables

Create variables:

PRIVATE_KEY - Private key without passphrase in "OpenSSH" format

SERVER_HOST - Host/ip remote server

SERVER_USER - User name of remote server

SERVER_PORT - Port of remote server

In remote server

Add public key without passphrase in ~/.ssh/authorized_keys in "OpenSSH" format

echo 'ssh-rsa xxxxxxxx....' >> ~/.ssh/authorized_keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment