2

I'm 100% new to AWS and I'm working on deploying my personal site. I've spun up an EB environment via the AWS EB CLI and but I would also like to be able to SSH into the EC2 instance that gets created however I can't locate the private key (.pem) file that is associated with it which I need to chmod for permit SSH'ing in.

Does a private key file get created when you create an EC2 instance via Elastic Beanstalk? If so where can I find it? Thanks a ton.

jl0w
  • 121
  • 1
  • 6
  • 1
    If you don't already have it, I don't think you'll "find" it anywhere... it has to be generated. With EC2 it's usually generated by the system and you get exactly one chance to download it -- when it's first generated -- but it looks like EB may do things differently... not sure if this is useful: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-ssh.html – Michael - sqlbot May 14 '17 at 02:00

2 Answers2

3

It is so valuable question for the AWS beginners. I was also confused with this question but get clear after a while.

I know you used the EB CLI for handling the EB. With the EB CLI you don't need the .pem file for normal use. Because the EB CLI has 'eb ssh' for connecting the EC2 instance of your EB. Please check out : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-ssh.html

Also you can't get the standard .pem file of your EB. There are some steps. Please check out : SSH to Elastic Beanstalk instance

smartworld-dm
  • 840
  • 9
  • 19
0

Elastic beanstalk still provisions EC2 instances and an SSH key can be assign to them.

You have two options if you didn't attach a key to an instance at provision time or have since lost it.

  1. Provision a new instances with a key attached to it.
  2. Snapshot the instance, Provision a new instances with a key attached and references the snapshot id of the old instance.

One should be easier with Elastic Beanstalk, just provision a new environment with keys attached to the instance, you will lose data with this method though.

More in depth steps for #2 can be found here . This will help you retain data if need be.

eb ssh only works if you have the keys and have attached them to the instance. Private key files must be located in a folder named .ssh under your user directory

eb init will ask if you want to ssh into your instance, then list out the keys in your account in that region. If a new key was created it should have outputted where the key was place on your filesystem.

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-init.html

eb create has a -k key option as well

If you include this option with the eb create command, the value you provide overwrites any key name that you might have specified with eb init. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-create.html

strongjz
  • 3,574
  • 1
  • 14
  • 21