title: Permission denied (publickey) while accessing aws through ssh
body: <p>I am trying to connect to my ec-2 free(t2.micro) instance through ssh from my PC. </p>
  
  <p>I have created instance with default VPC. I am not able to connect it from my PC. </p>
  
  <p>It is throwing me permission denied error. </p>
  
  <p>I have checked the rules in the security group. </p>
  
  <p>I have gone through the below url's to check the answer but no success.</p>
  
  <p><a href="https://stackoverflow.com/questions/23392763/aws-ssh-connection-error-permission-denied-publickey">AWS SSH connection error: Permission denied (publickey)</a></p>
  
  <p><a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html" rel="nofollow noreferrer">Troubleshooting Connecting to Your Instance</a></p>
  
  <p><a href="https://forums.aws.amazon.com/message.jspa?messageID=593715" rel="nofollow noreferrer">SSH: Permission denied (publickey)</a></p>
  
  <p>Also when I run below command</p>
  
  <pre><code>sudo ssh -v -i tep-keyPair.pem ubuntu@ec2-52-XX-XXX-XX.us-west-2.compute.amazonaws.com
  </code></pre>
  
  <p>The below error came:</p>
  
  <pre><code>OpenSSH_7.3p1, LibreSSL 2.4.1
  debug1: Reading configuration data /etc/ssh/ssh_config
  debug1: /etc/ssh/ssh_config line 20: Applying options for *
  debug1: Connecting to ec2-52-XX-XXX-XX.us-west-2.compute.amazonaws.com [52.XX.XXX.XX] port 22.
  debug1: Connection established.
  debug1: permanently_set_uid: 0/0
  debug1: key_load_public: No such file or directory
  debug1: identity file tep-keyPair.pem type -1
  debug1: key_load_public: No such file or directory
  debug1: identity file tep-keyPair.pem-cert type -1
  debug1: Enabling compatibility mode for protocol 2.0
  debug1: Local version string SSH-2.0-OpenSSH_7.3
  debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
  debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
  debug1: Authenticating to ec2-52-XX-XXX-XX.us-west-2.compute.amazonaws.com:22 as 'ubuntu'
  debug1: SSH2_MSG_KEXINIT sent
  debug1: SSH2_MSG_KEXINIT received
  debug1: kex: algorithm: curve25519-sha256@libssh.org
  debug1: kex: host key algorithm: ecdsa-sha2-nistp256
  debug1: kex: server-&gt;client cipher: chacha20-poly1305@openssh.com MAC: &lt;implicit&gt; compression: none
  debug1: kex: client-&gt;server cipher: chacha20-poly1305@openssh.com MAC: &lt;implicit&gt; compression: none
  debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
  debug1: Server host key: ecdsa-sha2-nistp256                 SHA256:ZeJ4XQUfgLkaMUEvjGohL/6FWKN9Gq4AXrPwL/i9t3M
  debug1: Host 'ec2-52-XX-XXX-XX.us-west-2.compute.amazonaws.com' is  known and matches the ECDSA host key.
  debug1: Found key in /var/root/.ssh/known_hosts:3
  debug1: rekey after 134217728 blocks
  debug1: SSH2_MSG_NEWKEYS sent
  debug1: expecting SSH2_MSG_NEWKEYS
  debug1: rekey after 134217728 blocks
  debug1: SSH2_MSG_NEWKEYS received
  debug1: SSH2_MSG_SERVICE_ACCEPT received
  debug1: Authentications that can continue: publickey
  debug1: Next authentication method: publickey
  debug1: Trying private key: tep-keyPair.pem
  debug1: Authentications that can continue: publickey
  debug1: No more authentication methods to try.
  Permission denied (publickey).
  </code></pre>
  
  <p>Please help me.. I am really stuck here</p>