EC2 instance always ask me to enter passphrase for the pem during connection
Solution 1:
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"
Solution 2:
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.
Solution 3:
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