Skip to content
TrySitePrice

How to limit SSH (TCP port 22) connections with ufw on Ubuntu Linux

Best/Tutorial

You can limit SSH (TCP port 22) connections with ufw (Uncomplicated Firewall) on Ubuntu Linux by following these steps:

  1. Install ufw if it's not already installed:
sudo apt-get install ufw
  1. Enable ufw:
sudo ufw enable
  1. Allow incoming SSH connections:
sudo ufw allow 22/tcp
  1. Limit the rate of incoming SSH connections:
sudo ufw limit 22/tcp

This will limit the rate of incoming SSH connections to 20 connections per minute by default.

  1. Verify the ufw rules:
sudo ufw status numbered

This will show you the rules that have been added to ufw, with the number of each rule.

Note: If you need to make further changes to the ufw rules, you can use the sudo ufw delete <rule number> command to delete an existing rule and sudo ufw insert <position> <rule> command to insert a new rule at a specific position.

These steps will limit the rate of incoming SSH connections to 20 connections per minute, protecting your server from SSH-based brute force attacks.