Home / DevOps / Configuring GitLab CI/CD for AWS Deployment Using SSH Keys

Configuring GitLab CI/CD for AWS Deployment Using SSH Keys

Setting Up Secure SSH Connections Between GitLab and AWS

Here’s a step-by-step guide to configure GitLab CI/CD pipelines for deploying to AWS EC2 instances using SSH key authentication:

1. Key Preparation

  1. Convert PPK to PEM (using PuttyGen):
    • Open your existing PPK private key in PuttyGen
    • Navigate to Conversions → Export OpenSSH key
    • Save as a PEM file (e.g., my-key.pem)
  2. Add the PEM file content to GitLab:
    • Go to your project → Settings → CI/CD → Variables
    • Add a new variable:
      • Key: SSH_PRIVATE_KEY
      • Value: Content of your PEM file
      • Check “Mask variable” and “Protect variable” options
  3. Generate public key from pem file and append that to AWS user .ssh/authorized_keys
    • Run the following command in your terminal (Linux/macOS/WSL)
ssh-keygen -y -f /path/to/your-key.pem > /path/to/your-key.pub

Leave a Reply

Your email address will not be published. Required fields are marked *