Wednesday, 16 February 2022

AWS SSH: Permission denied (publickey)

All of sudden ssh login to AWS via your private ssh key or via aws generated private key failed.

I.E ssh ubuntu@myawsip or ssh -i myawsprivate.pem ubuntu@myawsip all failed and produces :

Permission denied (publickey)

Follow the detail trouble shooting guide

https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-fix-permission-denied-errors/


If both error experienced, most likely is your home folder groups / permission at aws or your user folder groups / permission or your ssh folder groups / permission have changed.

https://forums.aws.amazon.com/message.jspa?messageID=334402


To fix

1) Connect to your ec2 instance via web :

 select your EC2 instance, on top left click "Connect" button,  the use default tab "EC2 Instance Connect",  click "Connect". This will open a web version terminal to your EC2 Instance


2) Check to see if your local computers ~/.ssh/id_rsa.pub is available on EC2 Instance ~/.ssh/authroized_keys. If not copy and paste it in


3) correct permission based on aws guide :

$ sudo chown root:root /home $ sudo chmod 755 /home

// Note for my case it will be ubuntu:ubuntu it is based on your ec2 user, aws example uses ec2-user $ sudo chown ec2-user:ec2-user /home/ec2-user -R $ sudo chmod 700 /home/ec2-user /home/ec2-user/.ssh $ sudo chmod 600 /home/ec2-user/.ssh/authorized_keys


end session, and you should be able to reconnect.


my issue is that my permission some how got changed 


More readings regarding permission :

https://phoenixnap.com/kb/ssh-permission-denied-publickey





No comments:

Post a Comment