Skip to content
Advertisement

SSH into AWS EC2 instance gives Permission denied (publickey)

I created a new EC2 Instance form my AWS Console and tried to ssh using my keyfile

JavaScript

I was able to login into the server and did these things :

installed httpd. isntalled php. installed mysql.

created a new group “web” and added user apache and ec2-user to this group.Changed my default home directory /home/ec2-user/ ownership to ec2-user:web

Set up FTP for my instance as explained in this answer.

then i installed OPencart in my home directory.

After this is logged out from the SSH using the exit command

but now when i try to login again using the same pem file i get this error:

JavaScript

Please Help.

Advertisement

Answer

This is the culprit.

Changed my default home directory /home/ec2-user/ ownership to ec2-user:web

sshd tried to get the public key from /home/ec2-user/.ssh/authorized_keys file but couldn’t because you changed the owner. So you are denied access.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement