Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 632
Michael Durrant Avatar asked Oct 10 '19 16:10

Michael Durrant


2 Answers

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

like image 163
Uberhumus Avatar answered Oct 12 '22 05:10

Uberhumus


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
like image 24
Ashaman Kingpin Avatar answered Oct 12 '22 04:10

Ashaman Kingpin