user1366073
user1366073

Reputation: 21

SSH Access to AWS EC2 - Permission Denied

I'm trying to access a new Ubuntu instance on EC2 using SSH. I've noticed a lot of people have got the same issue and have used different workarounds but have not been able to get this to work so far.

Any help would be much appreciated.

>$ ssh -l ubuntu -v -i TBKEY1.pem ec2-46-137-225-40.ap-southeast-1.compute.amazonaws.com  
>OpenSSH_6.0p1, OpenSSL 1.0.1b 26 Apr 2012  
>debug1: Connecting to ec2-46-137-225-40.ap-southeast-1.compute.amazonaws.com [46.137.225.40] port 22.  
>debug1: Connection established.  
>debug1: identity file TBKEY1.pem type -1  
>debug1: identity file TBKEY1.pem-cert type -1 [-pebug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-3ubuntu6  
>debug1: match: OpenSSH_5.3p1 Debian-3ubuntu6 pat OpenSSH_5*  
>debug1: Enabling compatibility mode for protocol 2.0  
>debug1: Local version string SSH-2.0-OpenSSH_6.0  
>debug1: SSH2_MSG_KEXINIT sent  
>debug1: SSH2_MSG_KEXINIT received
>debug1: kex: server->client aes128-ctr hmac-md5 none
>debug1: kex: client->server aes128-ctr hmac-md5 none
>debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent  
>debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP  
>debug1: SSH2_MSG_KEX_DH_GEX_INIT sent  
>debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY  
>debug1: Server host key: RSA 77:49:93:95:2f:c5:b2:9c:d3:1b:f0:34:fb:23:b1:8c  
>debug1: Host 'ec2-46-137-225-40.ap-southeast-1.compute.amazonaws.com' is known and matches the RSA host key.  
>debug1: Found key in /home/Ma/.ssh/known_hosts:1       
>debug1: ssh_rsa_verify: signature correct  
>debug1: SSH2_MSG_NEWKEYS sent    
>debug1: expecting SSH2_MSG_NEWKEYS    
>debug1: SSH2_MSG_NEWKEYS received  
>debug1: Roaming not allowed by server  
>debug1: SSH2_MSG_SERVICE_REQUEST sent  
>debug1: SSH2_MSG_SERVICE_ACCEPT received
>debug1: Authentications that can continue: publickey  
>debug1: Next authentication method: publickey  
>debug1: Trying private key: TBKEY1.pem 
>debug1: read PEM private key done: type RSA  
>debug1: Authentications that can continue: publickey  
>debug1: No more authentication methods to try.  
>Permission denied (publickey).  

Upvotes: 2

Views: 2854

Answers (3)

praitheesh
praitheesh

Reputation: 41

Since you are getting Permission denied (publickey) message from server there is no issue in connectivity. Make sure your key pair related to TBKEY1.pem is linked with your instance. If it is linked then it should appear as below screenshot.

enter image description here

You can find more details here

Upvotes: 0

shashankaholic
shashankaholic

Reputation: 4122

Use ec2-user as username.

Try command

ssh -l ubuntu -v -i TBKEY1.pem [email protected]

Upvotes: 1

Davide Vernizzi
Davide Vernizzi

Reputation: 1407

Once I had a similar problem. I was not able to solve it, but I worked around it. What you can do is to create an AMI from the EBS of the machine you are trying to access, then start a new instance out of that AMI and specify to create a new key pair. AWS should then add your new private key to the allowed_keys and let you into the new machine. At that point you can shoot down the old one.

Hope this helps.

Upvotes: 1

Related Questions