amazon-web-servicesamazon-ec2

EC2 access using .pem file and security


I have a terraform script which creates EC2 (bastion host) and emits out .pem file.


Solution

    1. Do not commit .pem files to version control.
    2. Use AWS Systems Manager for instance access instead of traditional SSH, wherever possible.
    3. Regularly audit and remove stale SSH keys from your EC2 instances, particularly when employees leave the company.

    EC2 key pairs​ Docs https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/key_pair