AWS EC2 Permission denied (publickey,gssapi-keyex,gssapi-with-mic

Issue:

 ssh -i "key-aws.pem" ec2-user@ec2-IP.compute-1.amazonaws.com

IP: 10.0.0.1

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for key-aws.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: key-aws.pem
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

[vagrant@vagrant-centos65]$ chmod 400 key-aws.pem
[vagrant@vagrant-centos65]$ ls -ltr key-aws.pem
-r-xr-xr-x 1 vagrant vagrant 1692  key-aws.pem

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0555 for 'key-aws.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: key-aws.pem
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Solution:

Follow the below steps and it will resolved for sure;
1. Copy the key-aws.pem into /home/vagrant/.ssh/
    cp key-aws.pem /home/vagrant/.ssh/
2. Change the file permission to read for that user only.
     chmod 400 /home/vagrant/.ssh/key-aws.pem
     [vagrant@vagrant-centos65]$ ls -ltr /home/vagrant/.ssh/
     -r-------- 1 vagrant vagrant 1692 key-aws.pem
3. Execute ssh command now.
    ssh -i "/home/vagrant/.ssh/key-aws.pem" ec2-user@ec2-IP.compute-1.amazonaws.com   

Happy learning and implementation!!

1 comment: