Hello I used to login from my terminal to my ec2 istance using this command

ssh -i mypemfile.pem ec2-user@my-ip

I have changed just the directory permission of my folder and and did this

sudo chmod -R  777 /home/ec2-user/

Now when I try to login it says

Permission denied (publickey)

Please help me how Can I go back. I am not able to login now

  • I just did the same i was trying to repermisin a directory and typed chmod -R 775 / into the command line after i logged out i cant ssh backin any more :-( – Yehuda Schwartz Jul 31 '18 at 13:24
  • 2
    You made your private ssh key readable/writable for every user. The ssh server probably doesn't like that. If you can't access your EC2 instance anymore, you probably have to contact Amazon support. – danzel Jul 31 '18 at 13:30
  • @YehudaSchwartz If you really did chmod -R 775 / then most likely not only your ssh is broken but much, much more. The often-heard advice in such cases is to reinstall because fixing a chmod -R 775 / isn't worth the effort. I wonder when people will eventually stop issuing this command... There is a reason why some files have these and some files have other permissions. – PerlDuck Jul 31 '18 at 13:42

I'm not familiar is there a backdoor for amazon-ec2, but you should find a way to log-in into your server and change the permissions of the ~/.ssh directory and it's content as follow:

chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/

See the topic "Permission denied (publickey)" within the section "Troubleshooting" of the article Public and Private Keys on the Ubuntu Documentation Wiki.

If the password authentication is not already disabled you can try to log-in by the following command (source):

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no user@host
  • i'm on DO i booted in recovery mode logged in through the console and tried this didnt help :-( – Yehuda Schwartz Jul 31 '18 at 13:53
  • 1
    @YehudaSchwartz That might be because you did not only break your home directory with the chmod -R but also the complete system by supplying / as the starting directory. – PerlDuck Jul 31 '18 at 13:57
  • so how can i fix??? – Yehuda Schwartz Jul 31 '18 at 14:30
  • @YehudaSchwartz, as PerlDuck said, probably you should reinstall the OS. – pa4080 Jul 31 '18 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.