Trouble deploying Docker Container to EC2 via SSH

Hey @gyfchong,
we were live analysing your Problem so here is our solution:

  1. encode your ssh-key as "base64 string "
    cat $HOME/.ssh/id_rsa | base64

  2. paste this your output in your CI/CD variable “$DEPLOY_SERVER_PRIVATE_KEY”

Afterwards your need to edit your gitlab-ci.yml

echo -n "$DEPLOY_SERVER_PRIVATE_KEY" | base64 --decode > ~/.ssh/id_rsa

Your .gitlab-ci.yml should look like the following than afterwards

script:
- echo -n "$DEPLOY_SERVER_PRIVATE_KEY" | base64 --decode > ~/.ssh/id_rsa
- chmod 700 ~/.ssh
- chmod 600 ~/.ssh/id_rsa

Here is also a short explanation of why you should doing this.

I hope this helps if you want to check the german recording you follow the following link below:

2 Likes