FabricioG
FabricioG

Reputation: 3310

Elastic Beanstalk ssh says it can't find my SSH key file

I'm trying to logon to an EBElastic Beanstalkinstance.

eb ssh

I then get the error:

ERROR: NotFoundError - The EB CLI cannot find your SSH key file for keyname "myName". Your SSH key file must be located in the .ssh folder in your home directory.

In the root directory of my project I have a directory:

.ssh

In it I've placed myName.pem and also just myName no extension.

-----BEGIN RSA PRIVATE KEY-----
abunchofcharacters...blahblah
-----END RSA PRIVATE KEY----

I'm not sure why this is not working. Any ideas as to why?

Upvotes: 6

Views: 5794

Answers (7)

tushortz
tushortz

Reputation: 5015

This solved it for me by re-running eb init in interactive mode.

eb init --interactive

Source aws docs

Upvotes: 0

srivas
srivas

Reputation: 11

by default, eb ssh tries to find and use the key you set when configuring your elasticbeanstalk application. Anyway you can control that using -e flag. Documentation says:

  -e CUSTOM, --custom CUSTOM
    Specify an SSH command to use instead of 'ssh -i keyfile'. Do not include the remote user and hostname.

so for example, if you want to use a specific key you can use:

$ eb ssh -e 'ssh -i <location-of-the-key-you-want-to-use>'

I also use the following that helps me debug ssh issues:

$ eb ssh -e 'ssh -vvv'

Upvotes: 1

stun
stun

Reputation: 1744

When I copied-and-pasted my LOCAL ~/.ssh/id_ed25519.pub into EC2 Key Pairs for import, I named it something else ("myName" in your case) in the AWS user interface, and I was getting the same error message with eb ssh.

So I duplicated my LOCAL SSH file pair to match the EC2 Key Pair name like this, and the error went away.

# MUST exactly match your EC2 Key Pair name
cp ~/.ssh/id_ed25519 ~/.ssh/myName
cp ~/.ssh/id_ed25519.pub ~/.ssh/myName.pub

Upvotes: 0

736f5f6163636f756e74
736f5f6163636f756e74

Reputation: 81

I had the same problem.

EC2 gave me a .cer file. I put this in the correct location but when running eb create I got the same error as you.

All I did to fix it was change the extension to .pem and it worked.

Upvotes: 0

Moacir Petry
Moacir Petry

Reputation: 78

The solution for this situation could be that way:

Go to EC2=>Network & Security=>Key Pairs, click on Actions button and Import key pair, give a name for your key pair and in the next field put your key pair (from your local computer or whatever environment that you're using)

i.e. To get the key pair value in your environment:

cat ~/.ssh/id_rsa.pub

Upvotes: 1

Luisito Vega
Luisito Vega

Reputation: 1

On linux - try creating a new key pair using the eb shh --interactive command. read the docs: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-ssh.html

After you create a new keypair you will then need to go to your Elastic Beanstalk environment to update your security configurations to the new keypair.

Upvotes: 0

charliefortune
charliefortune

Reputation: 3200

You need to put the key file in the .ssh directory beneath your home directory, not the root directory of your project.

Linux

On a linux based machine you can get to the right directory with

cd ~/.ssh

This is where you need to put your key file.

Windows

On a Windows machine, the directory you need to put the key file in will be something like

C:\Users\[ACCOUNT NAME]\.ssh

Swap [ACCOUNT NAME] out for whatever your Windows account is called.

I would also highly recommend generating a new key pair and removing the existing one - the one you have has now probably been committed to version control, or is sat in the project root on your ELB instance. Both scenarios are a massive security risk.

Upvotes: 9

Related Questions