amazon-web-servicesamazon-ec2sshpem

AWS EC2 Pem Permission denied (publickey) Except for master pem


I keep getting Permission denied (publickey) error every time I try to ssh into my ec2 instances using anything except for the master pems. I've tried going through the aws dashboard to create pem files and using the aws cli; neither work. I've tried with more than one instance, same thing everytime; master pem works all others don't.


Solution

  • When connecting to a Linux computer using SSH, the following process takes place:

    Therefore, to login to a Linux computer:

    When launching an Amazon EC2 instance for the first time, you can specify a keypair. The EC2 service will automatically place the corresponding public key in the /home/ec2-user/.ssh/authorized_keys file. This is why your "master key" is working.

    Simply creating keypairs in the console does not grant access to an instance. This is why your "other" keys are not granting access. For each of them that you want to work, you will need to put the corresponding public key in the ~/.ssh/authorized_keys file. You can put these public keys in other home directories too (eg /home/badhabit/.ssh/authorized_keys). This will permit the user with the matching private keypair to login as the badhabit user.