Secure Your Proxmox Server: Firewall, SSH and Fail2ban | Homelab From Scratch #2
Fresh out of the installer, Proxmox is wide open. Here's how I lock it down before installing anything on it: firewall, SSH with a hardware key, fail2ban and the basics, in an order that won't lock you out.
Installing Proxmox is the easy part. What almost nobody tells you is how the server looks right after the installer: root logs in with a password over SSH and the web UI, the firewall is off, and the repository it comes configured with is a paid one, so you don’t even get updates. It’s like a house with every door and window wide open.
In the last video I installed Proxmox on my 2013 HP ProLiant. In this one, before installing any service on it, I lock everything down: I leave a single door and give it a key nobody can copy. Here I walk you through every step, why I do it and in what order. Because when you secure a server, the most common mistake isn’t forgetting a setting: it’s locking yourself out of your own server.
This is part 2 of Homelab From Scratch, the series where I build a home lab, one service at a time.
In this video
- How to switch to the free repository and update Proxmox.
- Why Proxmox has two firewalls and why you need to turn on both.
- How to log in over SSH with your own user and a key stored on a YubiKey.
- How to turn off root and password logins, and change the SSH port without locking yourself out.
- Fail2ban for SSH and the web UI, the time zone, your certificate and the first images: virtual machine or container?
First, the free repository
Remember the “No valid subscription” warning? Proxmox comes configured with the enterprise repository, which is a paid one. Without a subscription you can’t download anything from it, and your server never gets updates.
In Updates → Repositories, disable the enterprise repositories and add the No-Subscription one. It’s free and it’s the right one for a lab; Proxmox doesn’t recommend it for production, and its documentation says so clearly.
Then update from the shell. On Proxmox you use apt full-upgrade, not a plain apt upgrade, because an update may need to install or remove packages. If the kernel was updated, reboot.
One detail so it doesn’t worry you: the subscription warning will keep showing up every time you log in. It’s just a reminder.
The firewall: two switches
This is called hardening: making a system stronger by removing what it doesn’t need and closing what comes open. To see what’s open, ss -tulpn shows you every service that’s listening: the web UI on 8006, SSH on 22 and others you probably don’t even use. And the firewall, off.
Proxmox has two firewalls, and this is where almost everyone gets confused:
- The Datacenter one is the main switch: it applies to every server and comes off.
- The node one belongs to each server: it comes on, but it does nothing while the main switch is off.
That’s why you configure both. I put the rules in the Datacenter, so they apply to every server: first, accept 8006 (the web UI); second, accept 22 (SSH); third, DROP everything else. They’re read from top to bottom and the first match wins. On my home network I leave them open to any source; if your server is on the internet, limit them to a list of trusted IPs.
Before you turn it on, keep an SSH session open in case you lock yourself out; that’s what Proxmox’s own documentation asks you to do. Then, in Datacenter → Firewall → Options, set Firewall: Yes and Input Policy: DROP: anything that arrives and doesn’t match a rule gets dropped. The node one is already on; leave it that way.
Proxmox also has an anti-lockout rule: from the local network it still lets you reach the web UI and SSH even with the policy set to DROP. But that rule covers port 22, not the new port you’re going to use for SSH. Keep that in mind for later.
Your own user and a key that can’t be copied
Right now, the SSH door is opened by root with a password. The first step is to create your own user (itslucho in my case) with a long password you’ll only use for sudo. Proxmox doesn’t ship with sudo, because it’s meant to be managed as root, so you install it and add your user to the group that can use it.
Now the key. A password is like a standard key: it can be guessed or copied. My SSH key isn’t even on my computer: it lives inside a YubiKey 5C NFC. From my Mac I get the public key from the YubiKey, copy it to the list of authorized keys of my user on the server (the only keys that can get in) and test it: the YubiKey blinks, I touch it and I’m in.
You don’t need a YubiKey for this. A regular ed25519 key created on your computer works too, and both paths are in the repo. If you’d rather use a FIDO2 key (ed25519-sk), keep in mind that the SSH that ships with macOS doesn’t support it: you need OpenSSH from Homebrew.
What if I lose the YubiKey? I have the same key on a second YubiKey, stored away.
Lock down SSH and change its port
With the key working, you can close everything else in /etc/ssh/sshd_config:
PermitRootLogin no: nobody logs in directly as root.PasswordAuthentication noandPermitEmptyPasswords no: no passwords, not even empty ones; key only.AllowUsers itslucho: the only user who can log in is yours.ClientAliveInterval 100andClientAliveCountMax 3: they close sessions that stop responding, after about five minutes.X11Forwarding no: turns off graphical window forwarding, which you don’t use on a server.
Watch out for a Debian detail: the start of that file includes everything in /etc/ssh/sshd_config.d/, and for each setting the first value wins. So after changing it, check the configuration that’s actually active with sshd -T.
And the port. Bots try port 22 all day long. Changing it doesn’t make you invincible (anyone who scans every port will find it), but your door is no longer where everyone looks for it, and it takes a lot of noise out of your logs. Use a number between 1024 and 32767 that no other service uses: below 1024 are the system ports, and from 32768 up Linux uses ports for its own outgoing connections. And better avoid 2222: it’s the most common alternative and it gets scanned too. In the examples I use 24816.
The order that keeps you from locking yourself out
This is where a lot of people lock themselves out of their own server: they change the port or turn off passwords, restart SSH and close the only session they had open. The safe order is this one:

- Make sure you already log in with your user and your key.
- Open the new port in the Datacenter firewall, with an ACCEPT rule above the DROP (the anti-lockout rule doesn’t cover it).
- Check the configuration with
sshd -t: no output means it’s fine. - Restart SSH without closing the session you have open.
- Test the new port in another terminal: your user gets in; root doesn’t.
- Only then delete the port 22 rule.
Fail2ban: the one watching the door
What if someone tries passwords on the web UI over and over? That’s what fail2ban is for: it reads the logs and, if an IP fails several times, it bans it for a while.
Proxmox 9 has a change that breaks a lot of older guides: there’s no /var/log/auth.log anymore, because the system doesn’t ship with syslog. Everything goes to the systemd journal, so fail2ban has to read from there (backend = systemd).
The setup follows the official Proxmox guide. You copy jail.conf to jail.local, a file of your own that updates won’t overwrite, and enable two jails:
- sshd, with the new port.
- proxmox, for the web UI on 8006, with a filter that looks for failed Proxmox logins: three failed attempts in two days, and the IP is banned for one hour.
I tested it from my phone: one, two, three wrong passwords… and the page stopped loading. Banned by my own server. With fail2ban-client you can see the banned IPs and unban yourself.
One thing, though: fail2ban is an extra layer, not a reason to leave the Proxmox web UI exposed to the internet.
The time and the browser padlock
Two details that look minor. The time zone, in System → Time: I set America/Bogota; you set yours. If the time is wrong, your logs won’t add up when you’re trying to find out what happened.
And the connection not secure warning from the last video. I have a wildcard certificate for itslucho.com, so in System → Certificates → Upload Custom Certificate I paste the private key (without a passphrase) and the full certificate chain. I reload, and the warning is gone. If you don’t have a certificate, Proxmox includes ACME to get one for free from Let’s Encrypt and renew it automatically; you can also use certbot.
For now, pve.itslucho.com is resolved by the hosts file on my Mac; in an upcoming video I’ll move it to a local DNS.
The first images: VM or container?
And now, what I promised in the last video. In the local storage, ISO Images → Download from URL, you paste the link to an ISO (I used Debian’s) and Proxmox downloads it directly. In CT Templates, the Templates button has ready-made container templates: I downloaded Debian 13.
When should you use a virtual machine and when a container? Back to the house:
- A VM is a detached house: its own complete system, with its own kernel.
- A container is an apartment: it shares the foundations, the server’s kernel. That’s why it’s lighter and starts in seconds, but it only runs Linux and isolates less.
My rule: if it’s a Linux service, container. If it’s Windows, needs its own kernel or is something I don’t fully trust, VM. And if you’re going to use Docker, put it in a VM too: that’s what Proxmox recommends for the best isolation.
Your turn
Turn on both firewalls, create your user with a key and turn off SSH passwords. With your Proxmox and an SSH key (you don’t need a YubiKey), you can do it all in an afternoon.
Commands
After switching to the free repository, refresh the package list and install every update:
apt update
apt full-upgrade
See which services are listening and on which ports:
ss -tulpn
Create your user, install sudo and add your user to the group that can use it:
adduser itslucho
apt install sudo
usermod -aG sudo itslucho
From your computer: show the public key the agent has (the YubiKey one), copy it to your user on the server and test that you can log in:
ssh-add -L
ssh-copy-id itslucho@pve.itslucho.com
ssh itslucho@pve.itslucho.com
After editing sshd_config: check it has no errors, see the values that are actually active and restart the service:
sudo sshd -t
sudo sshd -T | grep -Ei '^(port|permitrootlogin|passwordauthentication|permitemptypasswords|allowusers) '
sudo systemctl restart ssh
In another terminal, without closing the one you have open, test the new port (24816 is an example):
ssh -p 24816 itslucho@pve.itslucho.com
Install fail2ban and create your own configuration file:
sudo apt install fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
The two jails in /etc/fail2ban/jail.local:
[sshd]
enabled = true
port = 24816
backend = systemd
[proxmox]
enabled = true
port = https,http,8006
filter = proxmox
backend = systemd
maxretry = 3
findtime = 2d
bantime = 1h
The web UI filter, in /etc/fail2ban/filter.d/proxmox.conf (exactly as in the official guide):
[Definition]
failregex = pvedaemon\[.*authentication failure; rhost=<HOST> user=.* msg=.*
ignoreregex =
journalmatch = _SYSTEMD_UNIT=pvedaemon.service
Restart fail2ban, test the filter against the journal, see the banned IPs and unban yours (replace the IP with the one that got banned):
sudo systemctl restart fail2ban
sudo fail2ban-regex systemd-journal /etc/fail2ban/filter.d/proxmox.conf
sudo fail2ban-client get proxmox banned
sudo fail2ban-client unban 192.168.1.23
If you’d rather download the container template from the shell: refresh the list, find the exact name and download it:
pveam update
pveam available --section system
pveam download local debian-13-standard_<version>_amd64.tar.zst
Every sshd_config setting, an example firewall and the fail2ban files are explained one by one in the GitHub repo.
Resources & references
- Proxmox VE Firewall — Proxmox admin guide
- Firewall — Proxmox wiki
- Package Repositories — Proxmox wiki
- System Software Updates — Proxmox admin guide
- Fail2ban — Proxmox wiki
- Certificate Management — Proxmox wiki
- Proxmox Container Toolkit — Proxmox admin guide
- sshd_config(5) — Debian manual
- IANA port registry
- SANS ISC: activity on ports 22 and 2222
- Yubico: SSH with the YubiKey
Chapters
- 00:00 An open house
- 00:32 Free repository and updates
- 01:07 The firewall: two switches
- 02:22 My own user and a key that can’t be copied
- 03:10 Locking down SSH and changing the port
- 04:03 Fail2ban
- 04:52 Time zone and certificate
- 05:31 First images: VM vs container
- 06:20 What’s next
Series
Homelab From Scratch, part 2.
- ← Previous: Install Proxmox on an Old Server, where I took the server out of a closet and installed Proxmox on it.
- Next →: Plex on Proxmox: Your Movies on Your TV from an Old Server, where this server gets its first service.
Code
- 💻 Commands & files: github.com/itslucho-com/proxmox-hardening