Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH to AWS EC2 issue - key_load_public: No such file or directory [closed]

unfortunately 3 hours of googling is not helping me on this one and I'm counting on someone out there who can walk a 'nix noob through all this.

my situation

I have been ssh-ing successfully into my AWS instance from my mac for months. even today it was working. this logically eliminates all the setup-related issues like making sure i have port 22 open, directing to 0.0.0.0/0, having the right username (its ubuntu not ec2-user), having my pem file correctly permissioned, etc.

then my mac hangs, i restart the mac, and suddenly i can no longer ssh. i can't even ssh in through the java client launched straight from the aws console. utilization and other status checks on the aws console look fine.

here is my -vvv with personal info replaced:

OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to <myip> [<myip>] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/<myfilepath>/ipythonswyx1.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/<myfilepath>/ipythonswyx1.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
ssh_exchange_identification: read: Operation timed out

i figure it is fairly obvious that debug1: key_load_public: No such file or directory is the problem here. however a) why would this suddenly stop working? b) even after i chmodded the pem file again, it is still showing this error?

the only other solution i can find online is to delete this instance and just re set up from scratch - i would very much like to keep this instance.

can you please suggest things i should google or any other diagnostics i can run? the problem with being such a n00b is i dont even know the right questions to ask or how to describe my problem other than "this thing that worked now doesnt work and i have no freaking idea why". HELP.

like image 250
swyx Avatar asked May 25 '16 08:05

swyx


1 Answers

open a shell as your user

type this command

find $HOME -name ipythonswyx1.pem -print

This should find the path to your key. If it doesn't there are some other possiblities:

  • the key has a different name to the one shown in the the output above
  • the key is under a different user account
  • the key has been accidentally deleted

Assuming the key is found, note the path and use it as the parameter "identityfile" on ssh. So, assuming that the path is /Users/Bob/.ssh/ipythonswyx1.pem and the host IP address is 54.3.4.5 then try this command

ssh -i /Users/Bob/.ssh/ipythonswyx1.pem [email protected]

If the key is not found then you need to make a new instance, detach the EBS volume from the old disk, attach the old EBS volume to the new instance, add a new key to the ".ssh/authorized_keys" file for the ubuntu user on the old EBS volume then unmount it and reattach to the old instance.

For more on this sequence of events (to change the key) see this answer on serverfault https://serverfault.com/questions/273664/how-do-i-change-the-key-pair-of-an-aws-instance-if-i-lost-my-pem-file and in more detail with step-by-step instructions here https://aws.amazon.com/articles/5213606968661598

like image 197
Vorsprung Avatar answered Sep 24 '22 05:09

Vorsprung