- The pem file is generated by AWS console
- I was able to connect using the EC2 remote web interface, using the same pem file
- The permission of pem is 600 already
Error..
ssh -i ~/test.pem -v [email protected]
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/john/test.pem
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/home/john/test.pem':
Anyone can help?
Most likely your
test.pem
is corrupt.To check if it is fine run
openssl rsa -check -in test.pem -noout
It should say "RSA key ok"
I have also faced this problem a few times and found a solution that works for me and hope will work for you too. Most of the time when we ssh into an ec2 instance(say instance 1) from another ec2 instance(say instance 2) that is connect via ssh from our local machine we need a private key file i.e a ".pem" file to authenticate the identity of instance-2 to connect to instance-1. When we copy the content of the .pem file from our local machine to instance-2, sometimes what happens is, we open the .pem file in a text editor and copy the content and when we paste the file content in the file created in instance-2, we copy it using some other text editor. Here the problem arises.
The solution is -> Always use the same text editor in both the machines to copy and paste the content of .pem files otherwise the format will be changed and you find yourself in trouble.
I had this issue when I was trying to login from a NAT instance that I set up. The NAT instance is not something I can specify (to the best of knowledge) what OS to use, and I presume that it is using AWS CentOS. Anyways, I was always being asked for a passphrase when trying to connect to an instance on my private network. Here was how i resolved it, although it wasn't entirely apparent to me at the time.
Hope this helps
I had the same issue, I was trying to ssh to a private ec2 instance from a public ec2 instance, and I kept getting the "Enter passphrase for key <>" "Permission denied (publickey)." error.
What I did was create a .ppk from the .pem file with PuttyGen, then copy-pasted the contents of that .ppk file into a new file created with vi editor. And then I was trying to ssh with this file. I realized the error from the contents of the file when I re-opened it again in vi editor, it was not the same as the .pem file originally downloaded. So, I removed the erroneous file, copy-pasted the contents from the .pem file to a new file created with vi editor, then was successful to ssh to my private instance from my public instance.
I had the same problem. I got a request to enter a passphrase when I connected through linux, even though I connected using puTTY without a passphrase. Here is how I solved it: When I needed to copy-paste the key, I opened it with notepad and copied from there, instead of using the puTTY key generator. Then when I did the 0600 and ssh everything worked without requesting a passphrase.
I had exactly the same, problem was in not valid pem file (i have created it by vim and paste there key value) but in someway format of pem file was not right. I have created the same pem file in windows using notepad and moved it to my linux machine. And than everything worked for me.
I faced the same issue in AWS.
I am trying to access the instance from a private subnet through public. Whenever i run the command
ssh -i key.pem ec2-user@**private ip**
(from a linux terminal), I get the following prompt:So what I did was to run the following command on the file:
$vi key.pem
I saw whatever .pem (private key) I copied from the notepad it has not copied fully.
It was missing part of the header:
-----BEGIN
.So i write again correctly and resolved the issue. I hope it would be helpful for some people.
Thanks
Yes I also faced the same issue. I just fixed mine now by going into the text editor, vi KeyPair.pem and making sure that ---BeGin and --End were both added along with the private key. Once I added those 2 lines, boom! Ubuntu was up and running! Thanks everyone. You are all amazing people!
facing issues connecting from your public instance to your private instances
my problem was my fudged up key file. When copying and pasting. I just used scp to copy the original to the public instance.
scp -i <yourkey>.pem <yourkey>.pem ec2-user@<publicip>:~/
this passed openssl checks
I faced the same issue. The best solution is to upload the private key to a private S3 bucket and then copy the file from the S3 bucket to your ssh client.