EC2 instance always ask me to enter passphrase for the pem during connection

Server Fault Asked by Howard on November 30, 2020

  1. The pem file is generated by AWS console
  2. I was able to connect using the EC2 remote web interface, using the same pem file
  3. The permission of pem is 600 already


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?

11 Answers

I faced same issue, while doing connecting my public instance to private instance, My issue is resolved.

You can to the below things.

  1. While copying key use editor and copy it properly.

  2. Or copy .pem key to s3 bucket and from their download it to public instance.

Answered by Rajesh on November 30, 2020

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!

Answered by Slightly Rude on November 30, 2020

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.

Answered by Kartik Sharma on November 30, 2020

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:

Enter passphrase of key.pem:

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:


So i write again correctly and resolved the issue. I hope it would be helpful for some people.


Answered by Subhashree Deo on November 30, 2020

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.

Answered by CH CHAITANYA on November 30, 2020

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"

Answered by ishandutta2007 on November 30, 2020

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.

Answered by Alex on November 30, 2020

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.

Answered by AdiZ on November 30, 2020

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.

Answered by Deb on November 30, 2020

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.

[ec2-user@ip-10-2-3-192 ~]$ sudo bash
[root@ip-10-2-3-192 ~]$ ssh -i /home/test.pem [email protected]

Hope this helps

Answered by ice.nicer on November 30, 2020

If you try to establish a ssh connection from a ssh connection on ec2, use notepad to open .pem file on your local machine. It will work 100% and won't ask you for any passphrase.

Answered by qobok on November 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP