Score:0

UFW firewall create connection issues

ma flag

I have installed UFW on my VPS server using apt install ufw when I use ufw enable to start the firewall, after that my putty session expires and I can no longer login with that ssh key I have either change ssh key or disable firewall or delete my entire OS and re-install it. I have checked and sure that when I start UFW firewall I cannot connect with ssh key to my vps.

  1. Firewall = UFW firewall
  2. Start Command = ufw enable
  3. Error reason = ufw firewall preventing connection with ssh key using putty or any other terminal
  4. Error Output = ssh: connect to host <VPS_IP> port <VPS_PORT> : Connection timed out
  5. OS used in VPS = Ubuntu 20.04
in flag
Before enabling `ufw` you will want to ensure OpenSSH is permitted through. You can do so like this: `sudo ufw allow in "OpenSSH"`. Without this, you block port 22 from receiving connections
Score:0
cn flag

You need to whitelist the SSH port before enabling UFW within SSH session. If it is already enabled you must use the virtual console of the VPS provider to whitelist the post.

There is a standard application profile for SSH: /etc/ufw/applications.d/openssh-server. So if you don't use a custom SSH port you can activate this profile by the command:

sudo ufw limit OpenSSH

In case a custom SSH port is in use you can create a custom profile as it is explained here: Is it ok to manually update a ufw profile? Or you can allow the port manually by a command as:

sudo ufw limit 2222/tcp
  • where 2222 is the custom port and tcp is the protocol you need to allow at that port.

In the examples above is used the command limit which is equivalent of allow but adds some brute force protection, which is appropriate for SSH.


Note when you remove UFW while it is enabled the rules issued by it remains in iptables so if you want to completely remove UFW first disable it.

Raghav Patel avatar
ma flag
Thank you @pa4080.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.