-1

Today I tried to ssh to my AWS instance, as usual but got a "Permision denied" error with -v giving me the following:

debug1: Next authentication method: publickey 
debug1: Offering RSA public key: localuser@localmachine  
debug1: Authentications that can continue: publickey  
debug1: Trying private key: serverkey.pem  
debug1: key_parse_private2: missing begin marker  
debug1: read PEM private key done: type RSA  
debug1: Authentications that can continue: publickey  
debug1: No more authentication methods to try.

If I try to log as root@my-ip.com it will authenticate, but show the message: "Please login as the user "ubuntu" rather than the user "root"."

Last time I logged I created a new user for a web page within a new group "webapps". I assigned the home directory of this user to be the same as the ubuntu user since it was convenient. I have also tried to log in as this user with no success.

Also, I tried generating a new pair of keys (loacally and uploading the public key, and from the AWS console and saving the private key locally).

I would really appreciate if someone can help me!

Edit:

The command I use normally is ssh -i serverkey.pem ubuntu@my-ip.com after failing I generated the ssh key locally and uploaded it to AWS and used ssh ubuntu@my-ip.com with the key stored at ~/.ssh

BMW
  • 42,880
  • 12
  • 99
  • 116
kerloom
  • 60
  • 6

3 Answers3

1

You can't change the key after created ec2 instance.

Do you have the backup of serverkey.pem, if not, you can't login this instance any more. Recreate the ec2 instance with new key is the only way to go.

BMW
  • 42,880
  • 12
  • 99
  • 116
  • I do have the key, I never lost it. I am suspecting it has something to do with assigning a new user and changing permissions on the home folder. – kerloom May 23 '16 at 14:46
0
debug1: Trying private key: serverkey.pem  
debug1: key_parse_private2: missing begin marker

Did you edit your private key file? Can you check the first line exactly is like this?

-----BEGIN RSA PRIVATE KEY-----

helloV
  • 50,176
  • 7
  • 137
  • 145
  • I didn't edit the key, and it does have this (exact copy paste): `-----BEGIN RSA PRIVATE KEY-----` – kerloom May 19 '16 at 17:37
0

For anyone stumbling here I think my problem was assigning the second user's home folder to ubuntu's home folder. Since this is insecure it messes with the SSH connection. I had to make another instance and recover the info attaching the old volume to the new server instance.

kerloom
  • 60
  • 6