-1

am not able to ssh to Amazon AWS from my kali nethunter device nexus 6p I get this error public key denied.

However I can easily ssh from my desktop without any issues, computer that has kali linux directly installed.

Here is the error.

──(rootkali)-[/sdcard/Download] └─# ssh -i kali-cloud.pem ec2user@ec2-x-x-x-x.us-east-2.compute.amazonaws.com @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@ Permissions 0660 for 'kali-cloud.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "kali-cloud.pem": bad permissions ec2user@ec2-x-x -x.us-east-2.compute.amazonaws.com: Permission denied (publickey).

Kindly suggest.

Regards Skorp

Paul
  • 2,755
  • 6
  • 24
  • 35
Skorp
  • 1
  • 1
  • 2
    I suggest reading the error message. It clearly says that your key's permissions are not suitable. As a result, key-based authentication fails. – berndbausch May 16 '21 at 05:31

2 Answers2

1

Private keys should be go-rw and public keys should be go-w at least. In other words, permission 0660 is bad. chmod go-rw or 0600

Note also that the parent directory must also not be writable to anyone but the owner, so it should be 700 or 750

The reasoning here:

  • A private key is pretty useless if it is readable to others.
  • Both public key or private key are pretty useless if they can just be rewritten by others, either directly, or by replacing the file in the directory.

It would be a security hole to not ignore them when either of these is possible.

user10489
  • 474
  • 1
  • 2
  • 12
  • Initially after getting keys from AWS I gave permission chmod 400 for kali-cloud.pem. now even after chmod go-rw it's not working same error – Skorp May 16 '21 at 05:48
  • Very likely the directory also has wrong permissions. I'll add that to the answer. – user10489 May 16 '21 at 05:57
0

First you have to change the permission of your .pem file using this command:

chmod 400 kali-cloud.pem

Second you have to use the correct username to connect with your ec2 instance i.e ec2-user instead of ec2user:

──(rootkali)-[/sdcard/Download] └─# ssh -i kali-cloud.pem ec2user@ec2-x-x-x-x.us-

asmath
  • 301
  • 1
  • 6