HeadlinesBriefing favicon HeadlinesBriefing.com

Prevent SSH Lockout When Enabling UFW on Linux

DEV Community •
×

A common mistake when securing a Linux server is locking yourself out via SSH after enabling a firewall. A new tutorial from DEV Community provides a step-by-step guide for safely configuring UFW (Uncomplicated Firewall). The key is to allow your SSH port *before* activating the firewall, ensuring you don't lose access during the critical moment of enabling the rules.

The guide walks through checking your current SSH port, adding the correct `ufw allow` rule, and setting default policies to deny incoming traffic. It emphasizes verification at every stage, using commands like `sudo ufw status verbose` to confirm rules are active. This methodical approach is essential for both new VPS setups and hardening existing servers.

Beyond the basic setup, the tutorial highlights a critical safety test: opening a second terminal to verify SSH connectivity before closing your original session. This practical check prevents the frustrating recovery process many admins face. For developers managing their own infrastructure, mastering this sequence is a fundamental skill for maintaining secure, accessible servers.