Search code examples
sshamazon-ec2ec2-api-tools

permission error to SSH EC2 instance


I want to SSH to one EC2 instance. I created the key pair using

ec2-add-keypair gsg-keypair

and change the access using

chmod 600 ~/.ec2/id_rsa-gsg-keypair

the keypair is:

-rw------- 1 hduser hadoop  1610 Nov  2 20:20 id_rsa-gsg2-keypair.pem

then I tried to SSH using

ssh -i id_rsa-gsg2-keypair.pem ec2-54-205-100-218.compute-1.amazonaws.com 

and it asked me to enter passphrase

Enter passphrase for key 'id_rsa-gsg2-keypair.pem':

and I do not have it. I tried to run it as root user, same error.I used the full path of the keypair file and got the same error. Finally I tried:

ssh -v id_rsa-gsg2-keypair.pem ec2-54-205-100-218.compute-1.amazonaws.com 

and got this:

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
ssh: Could not resolve hostname /home/hduser/ec2-api-tools-1.6.11.0/id_rsa-gsg2-keypair.pem: Name or service not known

it would be great if you can help me.


Solution

  • Firstly i would suggest to keep permission of the key file as 400 as it's too open. If your ami is ubuntu, then user name for ssh login should be ubuntu.

    so the command would be like ssh -i key.pem ubuntu@ec2-instace-address

    key.pem should contain the entire path to that file /home/ubuntu/.ssh where it's stored or run the above command from .ssh folder.

    `