0

I am new to Amazon AWS, I am trying to connect to my instance so I can upload my files and setup my database.

Initially on connection the console returned an error saying my keys permissions were incorrect, after correcting this the console returned a permission denied error.

imrans-macbook:WORK imran$ ssh -i MYKEY.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com
The authenticity of host 'ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com (xx.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is xx:xxx:xx:xxx:xxx:xxx:xxx.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': Yes
Warning: Permanently added 'ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com,xx.xxx.xxx.xxx' (RSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'MYKEY.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: MYKEY.pem
Permission denied (publickey).
imrans-macbook:WORK imran$ chmod 400 MYKEY.pem
imrans-macbook:WORK imran$ ssh -i MYKEY.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com
Permission denied (publickey).
InvalidSyntax
  • 8,035
  • 15
  • 63
  • 101

4 Answers4

1

What permissions did you change your key to?

The directory containing the key files should be set to 700.

chmod 700 ~/.ec2

The warning is telling you it's too open right now.

EFeit
  • 1,974
  • 14
  • 28
  • I changed the MYKEY.pem to 400, I've also just changed the directory it sits in to 700 but I'm still getting the permission denied error. – InvalidSyntax Apr 14 '15 at 14:14
  • Are you using a VPC on EC2? If so you would need to use the private DNS and not the public DNS. – EFeit Apr 14 '15 at 14:21
  • What AMI are you using? Did you try changing the key permissions to 600? – EFeit Apr 14 '15 at 14:26
1

Move your key to .ssh

.ssh should be set to 700

key should be 600

-

move your key to ~.ssh\yourkey.pem

rename your key to something else and then set to 600

greg_diesel
  • 2,770
  • 1
  • 13
  • 23
0

I resolved this by deleting my key pair and creating a new one along with a new instance. (nothing was on the old instance anyway)

InvalidSyntax
  • 8,035
  • 15
  • 63
  • 101
0

Private key file should have very limited permissions for it to work Use below command to change permissions

chmod 400 private-key-file.pem
Rai Ehtisham
  • 151
  • 1
  • 2
  • 11