SSH Connection timed out on EC2 Ubuntu

2.6k Views Asked by At

I am trying to secure my apache with Let's Encrypt on Ubuntu 18.04,

I ran these commands:

$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt install python-certbot-apache
$ sudo ufw enable
$ sudo ufw allow 'Apache Full'

After the last command, The terminal froze, so I decided to close it and reconnect hoping it would really reconnect.
Unfortunately, it returns with a message saying:

ssh: connect to host <...some public ipv4 DNS> port 22: Connection timed out

I checked the security groups to see if SSH is set to Anywhere and yes its set.

My guess is I messed up the ufw configs(or maybe not), but I can't confirm it because I cant ssh to my ec2 instance.

EDIT:
I tried stopping and starting the instance, causing it to change its public ip address, which I still cant ssh to :(

1

There are 1 best solutions below

0
On

Issue might be because ufw by default doesn't have allow 22 rule set, so before you enable ufw try running sudo ufw allow 22 or sudo ufw allow ssh.

To allow ssh before enabling ufw try running the below command which adds the rule to /etc/ufw/user.rules

sudo ufw allow ssh

So when user enables ufw it reads the already existing rules from the file, and doesn't terminate or block the user out of the access.

And then running the following commands will make it easy for the user to access the instance without any issues.

sudo ufw enable
sudo ufw allow 443
sudo ufw status

However, when coming to cloud provisioned instances, it's more likely and easy to play with security groups which would give a higher level of access to play with a specific instance and their corresponding rules.