Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to Amazon ec2 Instance without specifying .pem file

I have been using the following command to connect to my amazon ec2 instance from my OSX terminal:

ssh -i /path/my-key-pair.pem [email protected]

So I need to include the .pem file location on the command.

Is there any way, so that I do not need to specify the .pem file each time i connect?

Any help or suggestion will be appreciated. Thank you.

like image 517
Mohammad Saifullah Avatar asked Aug 31 '25 22:08

Mohammad Saifullah


1 Answers

Ok, i have got the solution. Here I am sharing if someone need sometimes:

  • Copy the .pem file to ~/.ssh
  • Create a config file at ~/.ssh

    touch ~/.ssh/config

  • open the config file in nano or vim. nano ~/.ssh/config

  • Add the following line to config file

    Host host_name

    HostName ec2.server.address.com

    User ec2-user

    IdentityFile "~/.ssh/ec2.pem"

  • Now connect from terminal: ssh host_name

like image 140
Mohammad Saifullah Avatar answered Sep 03 '25 13:09

Mohammad Saifullah