You can limit SSH (TCP port 22) connections with ufw (Uncomplicated Firewall) on Ubuntu Linux by following these steps:
- Install ufw if it’s not already installed:
sudo apt-get install ufw
- Enable ufw:
sudo ufw enable
- Allow incoming SSH connections:
sudo ufw allow 22/tcp
- 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.
- 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.