SSH into Ubuntu EC2 instance post blocking port 22 with UFW – Cloud Computing

During the configuration of SSL security, we may accidentally or purposely block SSH for the instance to make the instance secure. But, what if we again want the same instance to SSH for certain changes.

Check UFW Status and Rules

At any time, you can check the status of UFW with this command:

By default, UFW will be disabled so you should see something like this:

If UFW is active, the output will say that it’s active, and it will list the rules that are set. For example, if the firewall is set to allow SSH (port 22) connections from anywhere, the output might look something like this:

If you kicked or logged out of the instance once the changes are done, you will be seeing the below results.

On SSH into the instance with your Public DNS through PuTTY below are the results which you are seeing as an error i.e. Network error: Connection Timed Out

Below error shows that even after all ports were opened outside, the instance is not able to SSH because of firewall software of Ubuntu at the system level. Let’s see how to resolve this kind of system related issue.

  • The solution to the issue:1: Take an image of the EC2 instance by selecting the instance ->Image-Create Image
  • Provide specification Image name, tick on no reboot and push the create image button
  • Then Select the image and click on launch
  • Go to instance type, select and click on Next
  • In the configuration instance, write the below commands under Advanced Details and click on next:

  • Click next and next tab and add security group similar as provided
  • Review and launch the instance and then try to SSH to the instance through PuTTY. You will be now able to add SSH inside the instance with this and you can terminate the old instance as the new instance with all the setup same as that of the old instance without any issue except the public IP and private IP change.

Leave a Reply

Your email address will not be published. Required fields are marked *