amazon-web-servicesamazon-ec2pem

Can I configure my .ssh/config file to use my aws pem file as default for all ec2 connections


current my .ssg/config has

Host git-codecommit.*.amazonaws.com
  User APKAS2GIPODK72AAAAAA
  IdentityFile ~/.ssh/codecommit_rsa

Host github.com
  User durrantm
  IdentityFile ~/.ssh/id_rsa

I believe I can add an entry for a specific EC2 machine that I want to ssh into.

Is there a way to make the pem file by a default for all my EC2 ssh connections (while I am using the awscli, configured for my account-user) so that I don't have to -i "abc.pem" for each ec2 connection?


Solution

  • Yes, you can if you connect to the instances via their public DNS. Add this to your SSH config:

    Host ec2-*.compute.amazonaws.com
        IdentityFile abc.pem
    

    This is identical to what you have with Host git-codecommit.*.amazonaws.com