Skip to content

Recovery after CSF locked the world out of a cPanel server

CSF set to deny by default with too few allowed IPs will lock everyone out, including you. Recovery is via the provider console, not SSH.

CSF (ConfigServer Security & Firewall) doing exactly what you told it to do is the classic admin mistake: enable deny-by-default with TESTING = 0 and an empty allow list, and SSH closes on you mid-edit. The console-level recovery is straightforward if you have provider console access; without it, the path requires a single-user-mode boot or KVM. Either way, the lesson is that CSF has a testing mode for a reason.

What’s happening

CSF runs as an iptables/nftables ruleset. When TESTING = 1 in /etc/csf/csf.conf, the rules expire after 5 minutes — exactly so you cannot lock yourself out. When TESTING = 0, the rules persist across reboots. If your allow list does not include your IP and the deny default is in place, you cannot SSH back in. CSF also has LFD (Login Failure Daemon) which can auto-ban an IP after failed logins, and that ban survives reboot.

How to verify

If you can still get a console (provider KVM, hypervisor console), check what CSF is doing:

csf -l                       # list current rules
cat /etc/csf/csf.conf | grep -E "^TESTING|^DENY_IP_LIMIT"
cat /etc/csf/csf.allow
cat /etc/csf/csf.deny
csf -t                       # active temp blocks (LFD)
journalctl -u lfd --since "1 hour ago"
# is your IP banned?
csf -g <your-ip>

If you cannot get a console at all, the provider’s “console access” or “rescue mode” is the next step.

The fix

  1. Console-only access — through the provider console, log in as root. csf -df <your-ip> to remove an LFD temp ban for your IP, csf -a <your-ip> to permanently allow.
  2. Stop CSF temporarily — csf -x (disable) restores connectivity immediately while you fix the config. SSH back in via your normal path, edit /etc/csf/csf.conf, re-enable with csf -e.
  3. Rescue mode if no console — boot the server in rescue mode, mount the root filesystem, edit /etc/csf/csf.allow to add your IP. Or simpler: rename /etc/csf/csf.deny to disable all deny rules on next boot.
  4. Re-enable TESTING mode for next change — TESTING = 1 in csf.conf, then csf -r. Future changes will time out after 5 minutes if they break connectivity, restoring access automatically.
  5. Document the allow list — write down which IPs are in csf.allow, why, and when they were added. CSF’s allow list grows incoherent over years; a comment per line helps future you.

The same pattern applies to nftables/iptables changes outside CSF — never change a deny-default firewall on a server you cannot get console to. Stack Harbor handles firewall change windows with rollback under WHM server management — start a conversation for the next CSF policy review.