Blog
Tutorial

Configure UFW on a Linux VPS and reduce SSH lockout risk

Confirm your SSH port, add access rules before enabling UFW, check IPv6, and keep the browser console available for recovery.

To set up UFW without cutting off SSH, confirm the port your SSH daemon listens on, allow that port before enabling UFW, then test a new SSH connection while your current session stays open.

Allow SSH before enabling UFW

A wrong or missing SSH rule can block your remote access, so identify the listening port before you change the firewall. The UFW manual (opens in a new tab) describes the firewall commands; the OpenSSH configuration manual (opens in a new tab) documents the daemon settings.

  1. Find the listening port

    In your current SSH session, run sudo ss -tlnp and look for the listening socket owned by sshd. If the port is unclear, check the SSH daemon configuration.

  2. Allow that port

    For the default SSH port, run sudo ufw allow 22/tcp. Replace 22 with the port you confirmed if your server uses another one.

  3. Check the rule before enabling

    Run sudo ufw show added and verify that the SSH allow rule is present. Do not enable UFW before this check.

Add web-server rules and check IPv6

Only open ports your service uses. A web server serving HTTP and HTTPS commonly needs inbound TCP rules for ports 80 and 443.

  • Allow HTTP with sudo ufw allow 80/tcp.
  • Allow HTTPS with sudo ufw allow 443/tcp.
  • Check /etc/default/ufw for IPV6=yes, then confirm your UFW version and system configuration handle IPv6 rules as expected.

Check that the active rules cover IPv6 as well as IPv4; do not assume an IPv4 rule is enough. UFW runs inside Linux, so its rules do not configure the separate firewall in your control panel.

Enable UFW and verify its status

Review the rules first, enable the firewall only after checking them, then test a second SSH connection before you close the first one.

  1. Review the added rules

    Run sudo ufw show added and check that the SSH port and any required service ports are allowed.

  2. Enable UFW

    Run sudo ufw enable.

  3. Inspect the active rules

    Run sudo ufw status verbose to check whether UFW is active and review its settings. Use sudo ufw status numbered to see rule numbers.

  4. Test a new SSH connection

    Open a second SSH session to the server. Keep the existing session open until the new one connects.

Know the lockout risk and recovery path

A missing or incorrect SSH rule can block remote access. A separate firewall can also block traffic even when UFW allows it.

If SSH stops working, use the browser VNC console in the control panel to inspect or change UFW rules. The Linux web terminal connects over SSH, so it is not a way back in if SSH is locked out. If you still cannot regain access, the control panel provides rescue mode, a root-password reset, and a rebuild option. See the firewall documentation (opens in a new tab) and VPS documentation (opens in a new tab) for control-panel details.

Disable or reset UFW

Disabling UFW turns off its filtering but does not remove the package. Resetting it clears its rules, so you need to rebuild the rules you require before enabling it again.

  • To turn off filtering, run sudo ufw disable.
  • To reset the rules, run sudo ufw reset and review the prompt before confirming.
  • Check the result with sudo ufw status verbose.

Separate host rules from VPS firewall rules

UFW runs inside Linux; the Ekire control-panel firewall is a separate layer. If both are enabled, allow each required port in both places. Review the firewall documentation (opens in a new tab) before changing the control-panel rules.

Frequently asked questions

How do I set up UFW on a Linux VPS?

Confirm the SSH listening port, allow it with UFW, review your rules, then enable UFW. Check the active status and verify a new SSH connection before closing your existing session.

How do I allow SSH before enabling UFW?

Find the port sshd listens on with sudo ss -tlnp, then allow that port. For the default port, run sudo ufw allow 22/tcp.

What UFW rules should I use for a web server?

If your server uses HTTP and HTTPS, allow TCP ports 80 and 443 with sudo ufw allow 80/tcp and sudo ufw allow 443/tcp. Also check the IPv6 setting and avoid opening ports your service does not use.

How do I check whether UFW is active?

Run sudo ufw status verbose. Use sudo ufw status numbered to inspect numbered rules.

Can UFW lock me out of my VPS, and how do I disable or reset it?

Yes. A missing or incorrect SSH allow rule can block access. Use sudo ufw disable to turn off filtering, or sudo ufw reset to clear the rules and rebuild them before enabling UFW again. If SSH is unavailable, use the browser VNC console in the control panel.

See compute detailsReview Ekire's KVM server details and deployment information.