↑ ↓ select, Enter open, Esc close

Enable ufw without locking yourself out

Adjust the values, the command updates live
root@server
ufw allow 22/tcp && ufw enable

Allows the SSH port and then enables ufw after a confirmation prompt. If the default policy is deny incoming, all ports that are not allowed are closed from the outside afterwards. If SSH runs on a different port, exactly that port must be entered, otherwise the server is only reachable through the hosting provider’s console.

Note: Check the prepared rules with ufw show added beforehand and keep a second SSH session open to test access after enabling. On web servers, also allow 80 and 443.

Open question before approval: Auf Plesk-Servern klären, ob ufw überhaupt verwendet werden soll oder ausschließlich die Plesk-Firewall-Erweiterung. Falls ufw: welche Ports (8443, 8447, 80, 443, Mail, FTP) vor dem Aktivieren freizugeben sind.

Also searched as

  • enable ufw without losing ssh
  • ufw allow ssh then enable
  • set up ufw firewall safely

Related one-liners

All in Firewall

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.