A patch panel with cables in a server rack
Security

How to secure a server when AI is the one scanning it: ports, SSH, fail2ban, audits and the rules

The terms worth knowing and a list of things to check on a server: open ports, SSH, fail2ban, Apache, RDP, patching, audits and penetration tests. Plus what PCI DSS v4 and US rules require.

16 min read

All articles

A server exposed to the internet does not wait long for its first visitors. Before you finish setting up the site, someone is already checking which ports are open, which SSH version answers and whether the password "admin" works. That has always been true: in a 2021 Unit 42 study, 80% of deliberately weak honeypots running SSH, RDP and databases were compromised within 24 hours, and all of them within a week. What is new is that a growing share of the attacker's work is now done by AI: faster, cheaper and without getting tired.

This article is for the business owner and for whoever "handles the servers" at the company. First a glossary, so a conversation with a vendor or an auditor is not guesswork. Then the concrete things to check, from ports to RDP. Finally the rules: PCI DSS and the US regulations that require most of this in writing.

What AI changed on the attacker's side

In November 2025 Anthropic described an espionage campaign by a group it attributed to the Chinese state: roughly thirty targets worldwide, with AI performing 80 to 90% of the work according to the report, from reconnaissance to exploitation. A small number of intrusions succeeded. 2025 was also the year XBOW, an autonomous penetration tester, reached first place on the HackerOne US leaderboard with more than a thousand vulnerabilities found automatically. The window for patching shrank too: according to VulnCheck, 28.96% of the vulnerabilities added to the KEV catalog in 2025 were exploited on or before the day their CVE was published, and Google's M-Trends 2026 puts the average time to exploit at minus seven days, meaning before a fix is released. In the Verizon DBIR 2026, exploiting vulnerabilities is for the first time the most common way in: 31% of breaches.

The conclusion for defenders is simple and uncomfortable. "We are too small to be a target" no longer works, if it ever did. Attackers do not pick a company. They pick a vulnerability and check the whole internet for anyone who has it. What matters is not how interesting you are, but how fast you patch and how many doors you leave open.

Glossary: the terms worth using

When you talk to a vendor, an admin or an auditor, these terms will come up. Know what they mean, and ask what exactly the other person means by them.

  • Attack surface. Everything an attacker can touch: open ports, services, login pages, plugins, accounts. All security starts with making it smaller.
  • Hardening. Turning off what is not needed and setting safe values on what stays. Default configuration is built for convenience, not for security.
  • Least privilege. Every account and every service can reach only what it needs. The application does not connect to the database as an administrator.
  • CVE and CVSS. A CVE is the ID of one publicly described vulnerability, such as CVE-2024-6387. CVSS is its score from 0 to 10. A high score does not always mean the problem applies to you.
  • RCE (remote code execution). An attacker runs their own commands on your server over the network. The worst class of vulnerability, because afterwards the server belongs to someone else.
  • Zero-day and n-day. A zero-day has no patch yet. An n-day is already fixed by the vendor, just not on your machine. Most breaches of small companies are n-days, which means missing updates.
  • KEV. CISA's Known Exploited Vulnerabilities catalog: flaws already used in real attacks. A good priority list: if it is in KEV, patch it first.
  • Brute force and credential stuffing. The first is guessing passwords over and over. The second is trying username and password pairs leaked from other services. The same things stop both: keys instead of passwords, and MFA.
  • MFA. Multi-factor authentication: a password plus something you have, such as an app or a hardware key. A stolen password alone stops being enough.
  • Bastion (jump host) and VPN. One well-guarded entry point that all administrative access goes through. No other server has management ports open to the world.
  • WAF. Web application firewall. It filters traffic to a site and blocks common attacks before they reach the application.
  • Segmentation. Splitting the network into zones so that breaking into one machine does not give access to all of them.
  • Vulnerability scan, audit, penetration test. Three different services that are often confused. We explain them below.
  • RPO and RTO. How much data you can afford to lose (RPO) and how long you can afford to be down (RTO). These two numbers decide how you do backups.

Ports: start with what the outside can see

A port is a numbered entrance to a service on the server. The website runs on 443, SSH usually on 22, PostgreSQL on 5432. Every port open to the world is a service anyone can poke at. The first and cheapest rule: everything closed by default, open only what has to be public. For a typical website or web app that is two ports: 80 and 443.

What should the internet see?

Public

  • 443

    HTTPS

    site and API, behind a reverse proxy

  • 80

    HTTP

    only a redirect to 443

Only through a VPN or bastion

  • 22

    SSH

    keys, no passwords, no root

  • 3389

    RDP

    never directly on the internet

  • 51820

    WireGuard

    the only door from outside

Never off the server

  • 5432

    PostgreSQL

    listens on 127.0.0.1

  • 3306

    MySQL

    listens on 127.0.0.1

  • 6379

    Redis

    no password by default

  • 2375

    Docker API

    full root, unencrypted

A typical split for a server running a web application. Databases and Redis should listen locally only.

Check it two ways. On the server you see what is listening and on which address. From the outside, from another machine, you see what an attacker sees. The two lists often differ, and the difference is the interesting part.

terminal
# on the server: what is listening, and on which addresssudo ss -tulpn # from another machine: what the internet can seenmap -Pn -p- your-server.com

If the database shows 0.0.0.0 instead of 127.0.0.1, it is listening on every interface. Then only the firewall stands between you and a leak, and sometimes not even that.

SSH: keys only

SSH is the standard remote way into a Linux server. It is encrypted and well tested, but the default configuration allows password logins, often including the root account. Shortly after a server goes online, password-guessing attempts start appearing in the logs. Three changes remove nearly all of that problem:

/etc/ssh/sshd_config.d/10-hardening.conf
PasswordAuthentication noKbdInteractiveAuthentication noPermitRootLogin noPubkeyAuthentication yesAllowUsers deployMaxAuthTries 3LoginGraceTime 20

Before restarting the service, test the configuration with sshd -t, and keep your current session open until you have logged in from a second window. Locking yourself out of your own server is the most common mistake with this change.

"SSH only": the pros and the cons

A common rule says: no admin panels in the browser, no FTP, no RDP, the only way into the server is SSH. It is a good rule, but know both sides of it.

  1. 01

    Pro: one door instead of five

    One service to watch, patch and log. A browser panel, FTP and a web file manager are three more places for a vulnerability to live.

  2. 02

    Pro: keys instead of passwords

    A key cannot be guessed or tried from a list of leaks. Brute force and credential stuffing stop making sense.

  3. 03

    Con: the door itself can have a hole

    In July 2024 Qualys described regreSSHion: remote code execution as root in the OpenSSH server, with no login. Keys did not help. Only the update did.

  4. 04

    Con: a key is a secret too

    A key without a passphrase on an employee's laptop is as safe as that laptop. When someone leaves, their key has to be removed from every server, and that is easy to forget.

That is why, once you run more than a couple of servers, SSH should not be open to the whole world. Put a VPN (WireGuard, for example) or a single bastion in front and allow SSH only from there. Moving SSH from port 22 to another port reduces noise in the logs, but it is not protection: a scanner finds SSH on any port in seconds.

fail2ban: what it does and what it does not

fail2ban reads the logs of services such as SSH, the web server or mail, and looks for failed logins. When too many come from one address in a short time, it adds that address to the firewall for a set period. It is a simple tool that has done its job for years, and it is worth having.

/etc/fail2ban/jail.local
[DEFAULT]bantime = 1hfindtime = 10mmaxretry = 5# each repeat ban of the same address lasts longerbantime.increment = trueignoreip = 127.0.0.1/8 ::1 [sshd]enabled = true

The defaults in jail.conf ban an address for 10 minutes after 5 failures within 10 minutes. For SSH that is lenient, so the example bans for an hour and grows the ban for repeat offenders (bantime.increment, available since version 0.11). Put your changes in jail.local, not jail.conf, because a package update will overwrite the latter.

Know the limits of fail2ban so you do not treat it as a shield:

  • It will not stop a single exploit. An attack on an RCE vulnerability is often one connection, not a hundred password attempts. There is nothing for fail2ban to count.
  • It struggles with distributed attacks. If every attempt comes from a different address, as it increasingly does with botnets and automation, no address ever crosses the limit.
  • It does not replace keys. With SSH passwords turned off, fail2ban mostly keeps the logs quiet. The real work is done by passwords being impossible to guess.
  • It can lock you out. Add your own fixed addresses to ignoreip before you mistype your password five times on a new laptop.

A badly configured Apache

The web server has to be public by definition, so its configuration is the one strangers look at most. The most common mistakes are not sophisticated:

  • Directory listing. Without an index file, Apache shows a list of every file in the folder, backups and database exports included.
  • A public `.git` folder or `.env` file. Someone deployed the site by copying the whole project folder. From .git the source can be rebuilt; from .env come database passwords and API keys.
  • A public `server-status` page. It shows visitor addresses and request URLs, sometimes with tokens in the parameters.
  • The version in the headers. By default Apache announces its version. That saves an attacker one step in picking an exploit.
  • An old version. Apache 2.4.49 let anyone read files outside the web root and, with mod_cgi enabled, run commands. Details below, in the section on RCE.
/etc/apache2/conf-available/hardening.conf
ServerTokens ProdServerSignature OffTraceEnable Off <Directory /var/www/>    Options -Indexes -Includes    AllowOverride None</Directory> # files and folders nobody should be able to download<FilesMatch "^\.(env|git|ht)">    Require all denied</FilesMatch>RedirectMatch 404 /\.git

RDP open to the world

RDP, Windows Remote Desktop, listens on port 3389 by default. Exposing it to the internet is a common start of a ransomware attack on a small business. The script repeats itself: a scanner finds the open port, a bot guesses the password or tries leaked ones, someone on the other end logs in, disables the antivirus and encrypts the disks.

A weak password is not the only risk. In May 2019 Microsoft patched BlueKeep (CVE-2019-0708): a flaw in Remote Desktop Services that could be exploited without logging in and could spread from machine to machine on its own, like a worm. Any server with RDP open to the world and without that patch could be taken over without knowing a password.

  • Never directly on the internet. RDP only through a VPN or an RD Gateway with MFA.
  • NLA turned on (Network Level Authentication), so users authenticate before a session is set up.
  • Account lockout after a few failures, and strong, unique passwords on accounts with remote access.
  • A separate admin account for remote work, not the one you use every day.

RCE and the supply chain: holes no configuration shows

Everything above can be fixed in configuration files. The most dangerous vulnerabilities, though, live in the software itself, and your configuration can be flawless. Three cases from recent years show it well:

  1. March 2024

    A backdoor in the xz library

    Andres Freund noticed SSH logins taking suspiciously long and found the cause: xz versions 5.6.0 and 5.6.1 contained a deliberately planted backdoor aimed at sshd. A supply chain attack. Nobody's configuration failed; the code came from a trusted source.

  2. July 2024

    regreSSHion in OpenSSH

    CVE-2024-6387: remote code execution as root in the OpenSSH server on glibc-based Linux, with no authentication. Versions from 8.5p1 up to, but not including, 9.8p1 were affected.

  3. October 2021

    Apache 2.4.49

    CVE-2021-41773: path traversal in Apache 2.4.49 that, with mod_cgi enabled, ended in remote code execution. The fix in 2.4.50 was incomplete (CVE-2021-42013); it was properly closed in 2.4.51.

The defense here is not cleverness but discipline: automatic security updates, a list of what runs on the server, and someone who reads vulnerability notices for that list. On Debian and Ubuntu the basis is unattended-upgrades. If the server is not restarted after a kernel or library update, the fix does not take effect until it is.

terminal
# Debian and Ubuntu: automatic security updatessudo apt install unattended-upgradessudo dpkg-reconfigure -plow unattended-upgrades # is any service still using an old library version?sudo needrestart -r l

A vulnerability scan, an audit and a pentest are three different things

  1. 01

    Vulnerability scan

    An automated tool checks service versions against known vulnerabilities. Cheap, fast, done regularly, say monthly or after every change. It tells you what is outdated, not whether it can be exploited.

  2. 02

    Audit

    A review against requirements: policies, configurations, permissions, procedures, documentation. It answers whether you do what you should, and whether you can prove it.

  3. 03

    Penetration test

    A person, increasingly helped by AI, actually tries to break in, chaining small weaknesses into one attack. Expensive and less frequent, but the only one that shows what an attacker would really achieve.

  4. 04

    When to use which

    Scans continuously, an audit when a rule or a client requires one, a pentest once a year and after every major change: a new application, a migration, a new vendor.

When you order a pentest, ask for the scope in writing (which addresses and applications), whether the test runs from outside, from inside or with a user account, and for a report that explains how to reproduce each finding. A scanner printout with a company logo on it is not a pentest.

The rules: PCI DSS and US regulations

PCI DSS v4: if you touch card data

PCI DSS is the payment card industry's security standard. It applies to anyone who stores, processes or transmits card data. The current version is 4.0.1, from June 2024, and the requirements once marked as future-dated have been mandatory since 31 March 2025. If a payment provider handles payments entirely, for example through a redirect to its own page, your scope is much smaller, but it does not disappear. For a server the key requirements are:

  • Vulnerability scans every three months: internal (11.3.1) and external, run by an Approved Scanning Vendor (11.3.2).
  • Penetration tests at least once every 12 months and after any significant change, internal and external (11.4). Segmentation is tested every 12 months, every six for service providers.
  • MFA for all access into the cardholder data environment (8.4.2), and passwords of at least 12 characters (8.3.6).
  • An automated technical solution protecting public-facing web applications, such as a WAF (6.4.2).
  • Only necessary services, protocols and daemons enabled (2.2.4), which is exactly what the section on ports was about.

US rules: which one applies depends on your industry

The US has no single federal law that tells every business how to secure a server. Instead, the obligations come from your industry, your customers' data and whether you are public. Most of them ask for the same things this article covers: MFA, encryption, scans, penetration tests and a plan for incidents. The ones a small or mid-size business meets most often:

  • FTC Safeguards Rule. Covers "financial institutions" under the GLBA, which is wider than it sounds: mortgage brokers, payday lenders, tax preparation firms, and auto dealers that arrange financing or lease for more than 90 days. It requires a Qualified Individual in charge, a written risk assessment, encryption, MFA for any individual accessing any information system, an annual penetration test (unless you monitor continuously) and vulnerability assessments every six months, a written incident response plan and an annual report to the board. Businesses with fewer than 5,000 consumers are exempt from the risk assessment, testing, response plan and board report, but not from MFA or encryption. An incident involving unencrypted data of at least 500 consumers must be reported to the FTC as soon as possible and no later than 30 days after discovery.
  • HIPAA Security Rule. Anyone handling patient data already has to run a risk analysis. A January 2025 proposal would add explicit MFA, encryption, scans every six months and an annual penetration test, but it is still only a proposal: final action is now projected for July 2027. Treat those items as good practice, not current law.
  • NY DFS Part 500. For banks, insurers and other entities licensed by New York's financial regulator. Since 1 November 2025 MFA is required for any individual accessing any information system, along with a written asset inventory. Incidents must be reported within 72 hours, and compliance is certified every year by 15 April.
  • SEC cybersecurity rules. Public companies disclose a material incident on Form 8-K within four business days of deciding it is material, and describe their security program in the 10-K. The SEC opened a review of its disclosure rules in 2026, so details may change, but the rules apply today.
  • CMMC. For defense contractors handling controlled unclassified information. The program rule took effect in December 2024; since 10 November 2026 contracting officers can require a third-party assessed Level 2 certification.
  • CIRCIA. Will require critical infrastructure operators to report significant incidents within 72 hours and ransom payments within 24. Not mandatory yet: as of late November 2026 CISA's final rule has not been published.
  • State laws. Every state has a data breach notification law; Alabama was the last, in 2018. A few states reward doing the work: in Ohio, a written security program that reasonably conforms to a recognized framework gives a business an affirmative defense against certain breach lawsuits, and Connecticut bars punitive damages for businesses with such a program.

A checklist for one server

  1. From outside, only the ports that must be public are open. Databases, Redis and the Docker API listen locally.
  2. SSH with keys only, no root login, ideally reachable only from a VPN or bastion.
  3. The firewall denies by default with reviewed exceptions, and Docker rules do not quietly bypass it.
  4. fail2ban runs for SSH and login pages, with your own addresses on the ignore list.
  5. Automatic security updates are on, and the server is restarted after kernel and library updates.
  6. The web server does not list directories, does not serve .git or .env, and does not reveal its version.
  7. RDP is not exposed to the internet, and remote access requires MFA.
  8. Backups run automatically, are stored off the server, and are actually restored as a test from time to time.
  9. Logs are shipped off the server, so an intruder cannot quietly wipe them.
  10. You know who has access, and you remove the keys and accounts of people who have left.

How we handle it

On the projects we deploy, the server is described in code from day one: open ports, users, keys, firewall and services live in the repository, not in someone's memory. That makes the configuration readable, reviewable and reproducible on a clean machine. We wrote about why fewer plugins mean a smaller attack surface in custom software with a smaller attack surface.

If you want us to look at your server or set up the infrastructure for a new project, write to us. We start where every attacker starts: with the list of what is visible from outside.

Building something similar?

Tell us about your project and we will get back to you with specifics.

Let's build

Keep reading