7

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?

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497

2 Answers2

7

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

Uberhumus
  • 921
  • 1
  • 13
  • 24
2

Yes, you can start an ssh-agent on your EC2 instance and have it load your private key. Then whenever you try and SSH to any instance that offers public key authentication, the ssh-agent will attempt to authenticate you using the loaded private key. This article describes it nicely.

eval $(ssh-agent) && ssh-add ~/.ssh/*.pem
Ashaman Kingpin
  • 1,467
  • 1
  • 11
  • 11