# Fail2ban and security updates

URL: https://docs.vaultpanel.net/guides/security/fail2ban-and-updates

> Block addresses that keep failing to sign in over SSH with Fail2ban, and keep servers patched with automatic daily security updates.

Two settings keep a server hard to break into over time: Fail2ban blocks addresses that keep guessing SSH passwords, and unattended-upgrades installs the operating system's security fixes every day. Both are managed per server. Viewing needs `security.read`; changes need `security.manage`.

## Brute-force protection with Fail2ban

Fail2ban reads the SSH log and blocks an address that fails to sign in too many times. Its card, **Brute-force protection**, is on **Security > SSH** and on each server's **Security** tab.

If Fail2ban is missing, click **Install Fail2ban**. The agent installs it together with `python3-systemd`, so Fail2ban can read the systemd journal; without that package it reads `/var/log/auth.log`.

### Settings

| Setting | Default | Range |
| --- | --- | --- |
| **Protect SSH** | | Starts Fail2ban now and at every boot |
| **Failed attempts** | 5 | 1 to 20 |
| **Within (minutes)** | 10 | 1 to 1440 |
| **Block for (minutes)** | 60 | 1 to 43,200 (30 days) |
| **Never block** | | Up to 20 addresses or networks, one per line |

The server itself is always on the **Never block** list. Add the addresses you work from; **Add my address** fills in yours as the panel sees it.

Saving writes `/etc/fail2ban/jail.d/vaultpanel.local`, checks it with `fail2ban-client --test`, enables and restarts Fail2ban, then checks that the SSH jail runs. If the jail does not start, the previous file is put back and the change fails with `JAIL_FAILED`: usually `python3-systemd` is missing (`apt install python3-systemd`), and `/var/log/fail2ban.log` has the details.

When you [move SSH to another port](https://docs.vaultpanel.net/guides/security/ssh#change-the-ssh-port), the jail follows the new ports.

### Blocked addresses

Below the settings the card shows how many addresses are blocked now, how many since Fail2ban started, and how many are failing now. Each blocked address has **Unblock**.

The **Failed SSH sign-ins** card next to it summarizes the last 24 hours from the journal, and **Block** adds a permanent [firewall](https://docs.vaultpanel.net/guides/security/firewall) rule for one address.

## Security updates

The **Security updates** card on each server's **Security** tab manages unattended-upgrades, the Debian and Ubuntu tool that installs security fixes from the operating system every day. It needs apt.

- **Install**: installs unattended-upgrades when it is missing.
- **Turn on** / **Turn off**: daily automatic security updates. The agent writes `/etc/apt/apt.conf.d/20auto-upgrades`.
- The number of security updates waiting, out of all waiting updates, counted with `apt-get -s upgrade` and cached for 6 hours.
- **Install security updates now**: runs `unattended-upgrade` at once. Services it updates restart, and it can take several minutes. The server is not restarted.

When installed updates need a reboot, the card says so; restart from the server page when it suits you.

To patch many servers, run **Install security updates** as a [bulk action](https://docs.vaultpanel.net/guides/servers/server-groups#bulk-actions). It runs one server at a time by default.

## Security checks

Both settings feed the [security overview](https://docs.vaultpanel.net/guides/security#security-overview): **Brute-force protection** is OK when Fail2ban runs and watches SSH, **Automatic security updates** when updates install every day, and **Waiting security updates** when none are waiting.
