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
- 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
)
- 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
- Key:
- 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