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

amazon ec2amazon-web-serviceslinuxSecurityssh

  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

Error..

ssh -i ~/test.pem -v ubuntu@ec2-1-2-3-4.compute-1.amazonaws.com

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?

Best Answer

If sharing a private key between 2 or more ec2 instances and if you try to establish a ssh connection from a ssh connection on ec2, use notepad to open .pem file on your local machine and copy the contents to the new .pem file you're creating in the ssh terminal. It will work 100% and won't ask you for any passphrase.

If you open your local .pem file with other text editors i.e. VSCode you will be asked for the passphrase when trying to use your new .pem file.