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

7

6

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?

Leopardi answered 16/9, 2019 at 21:32 Comment(1)
the directory should be like home/user/.ssh/Claudine
R
8

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.

Riposte answered 9/10, 2019 at 10:32 Comment(0)
C
1

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

Caddoan answered 12/6, 2021 at 14:37 Comment(0)
G
1

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'
Grecism answered 20/11, 2023 at 17:50 Comment(0)
E
0

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.

Eatable answered 29/5, 2021 at 15:57 Comment(0)
U
0

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.

Unveiling answered 1/9, 2022 at 13:4 Comment(0)
L
0

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
Leckie answered 5/6, 2023 at 0:20 Comment(0)
B
0

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

eb init --interactive

Source aws docs

Brisco answered 28/1 at 22:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.