Search code examples
amazon-web-servicesamazon-ec2permissions

AWS EC2 Connection (SSH) says - Connection refused


I was just connected to the instance over ssh and Change permission on home directory to 755 using "sudo chmod -R 755 ./". After that, I can't execute any single commands through SSH shell. So I have disconnect and find my ec2 public IP has been changed. Now i am trying to connect with ec2 instance using .pem file, it says connection refused and port 22 is showing as closed.

Note: I have tried to reconfigure security group inbound rule for port 22 and stop,start my instance but none of these worked.


Solution

  • That probably means sshd is down on your ec2 instance.

    1st thing: SSH is very sensitive to permissions; please refer to ssh-and-home-directory-permissions

    2nd thing: change of public IP means the instance was stopped/started, not just disconnected; an EC2 does not lose its public IP without a stop/start.

    So probably you broke your ssh access when changed permissions; and ssh might not have been enabled, so when you reboot the box, it was not started leading to connection refused error.

    You can try to connect through the console and troubleshoot; or follow this question EC2 SSH port 22 connection refused even though previously worked