Make repeated login attempts less useful
A cautious setup path for log-based blocking on a Linux server.
Content revised · English
- Guide type
- Operate & secure
- Examples
- Illustrative, environment-specific
- Integration scope
- No remote machine connected
Confirm the event and log source
Fail2ban reads authentication failures and asks a firewall backend to block repeated sources. It helps with repeated attempts; it does not replace key authentication or system updates. Confirm that SSH failures reach the journal or log file the jail will read.
Install the package for your distribution
On a maintained Debian or Ubuntu host the package manager can install it. Review its defaults and backend before enabling a custom jail. Other distributions may use a different package repository or firewall action.
sudo apt update
sudo apt install fail2banAdd a small override, not a copied global file
Create an override in /etc/fail2ban/jail.d/sshd.local. Match the actual SSH port. This example reads the systemd journal; use an appropriate backend and log path if the system writes a different log. Add a trusted administration address to ignoreip only after you have verified it.
[sshd]
enabled = true
port = 22
backend = systemd
maxretry = 5
findtime = 10m
bantime = 1h
ignoreip = 127.0.0.1/8 ::1Check configuration and the active jail
Start the service only after reviewing the file and keeping a recovery session open. Inspect the service and jail output; an active daemon with no matching events may provide no protection.
sudo fail2ban-client -t
sudo systemctl enable --now fail2ban
sudo fail2ban-client status
sudo fail2ban-client status sshdTest without losing the only access path
Use a separate controlled test source to verify detection, ban and expiry. Check IPv6 and the effective firewall rules. If a trusted source is incorrectly banned, use the retained console to remove that specific ban and then fix the policy; do not disable all protection to work around one mistake.
sudo fail2ban-client set sshd unbanip 192.0.2.44Leave with a verifiable result.
- Confirm the event and log source.
- Test without losing the only access path.
- Keep recovery information and secrets outside public files.