Run this on any AlmaLinux 9 server that has had a public IP for a day:
sudo journalctl -u sshd --since "24 hours ago" | grep -c "Failed password"
On a default install exposed to the internet, that count is rarely zero. Bots find port 22 fast. Here is a short checklist I use on new servers to cut that noise and close the obvious holes.
1. Put your SSH settings in a drop-in file
On AlmaLinux 9, /etc/ssh/sshd_config starts with an Include /etc/ssh/sshd_config.d/*.conf line. Don’t edit the main file. Create your own drop-in:
sudo tee /etc/ssh/sshd_config.d/00-hardening.conf <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
MaxAuthTries 3
LoginGraceTime 30
AllowUsers deploy
EOF
Replace deploy with your own admin user.
File order matters. sshd reads the drop-ins in lexical order, and for most keywords the first value it reads wins. That is why I name the file 00-, so it is read before the distro’s 50-redhat.conf. Don’t trust my reasoning or anyone else’s. Check the effective result on your own host:
sudo sshd -t && sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication|maxauthtries|allowusers'
sshd -t checks the syntax. sshd -T prints the configuration sshd actually uses. If a value is not what you wrote, another file is overriding it.
Before you reload: install your public key first (ssh-copy-id deploy@your-server) and confirm that key login works. Keep your current session open. Then run sudo systemctl reload sshd and test a second login in a new terminal. Only close the first session when the second works.
2. Keep firewalld tight
sudo firewall-cmd --list-all
sudo firewall-cmd --permanent --remove-service=cockpit # only if you don't use it
sudo firewall-cmd --reload
Cockpit is often enabled in the default zone. If you don’t need it, remove it. If you do need it, limit it to your own IP with a rich rule.
3. Ban repeat offenders with fail2ban
fail2ban comes from EPEL:
sudo dnf install -y epel-release
sudo dnf install -y fail2ban
sudo tee /etc/fail2ban/jail.d/sshd.local <<'EOF'
[sshd]
enabled = true
maxretry = 4
findtime = 10m
bantime = 1h
EOF
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
With key-only login, the bots cannot get in anyway. fail2ban mainly keeps your logs readable and saves some CPU.
4. If the same box also runs a proxy
Squid is in AppStream (dnf install squid). Two things are worth getting right.
First, never run an open proxy. Restrict it to known client IPs:
acl allowed_clients src 203.0.113.10/32
http_access allow allowed_clients
http_access deny all
Second, strip headers that leak information:
forwarded_for delete
via off
forwarded_for deleteremoves theX-Forwarded-Forheader. Without it, the destination site can see the address of the client behind the proxy.via offstops Squid adding aViaheader. That header announces that a proxy handled the request and can expose its hostname and software version.
Check the result with curl -x http://your-server:3128 https://httpbin.org/headers from an allowed client, and look at which headers arrive.
5. Check your work
sudo sshd -T | grep -i passwordauthentication
sudo ss -tlnp
sudo firewall-cmd --list-all
Three commands tell you what is listening, what is reachable and what sshd really accepts.
Disclosure: this post was written to introduce vpsttt, which offers VPS and proxy services. The steps above apply to any AlmaLinux 9 host.
What is the first setting you change on a fresh AlmaLinux 9 server?