Let’s say you want to setup a Gitlab server on AWS and you need to do a git clone using SSH protocol. You will be annoyed by the .pem file. To get rid of it (or more simply hide it) you can follow this procedure:

The pem file contains a private key. Simply extract it and add it to your system.


Copy the private key to the .ssh folder

cp /path/to/your/cert.pem ~/.ssh/id_rsa_gitlab_ec2

Generate a public key from the .pem file

ssh-keygen -y -f /path/to/your/cert.pem > ~/.ssh/id_rsa_gitlab_ec2.pub

Change private key file rights

chmod 600 ~/.ssh/id_rsa_gitlab_ec2

Add the private key to ssh-agent

# Start ssh-agent
eval "$(ssh-agent -s)"

# Add your newly created key to the agent
ssh-add ~/.ssh/id_rsa_gitlab_ec2

Now try to connect to you EC2 instance via SSH

ssh [email protected]

Try to git clone .... All good !