Skip to content

Moving SSH off port 22 and restricting AllowUsers on cPanel

A practical SSH hardening pass on cPanel — non-default port, AllowUsers list, and the CSF/cPHulk follow-ups that keep the change useful.

Moving SSH off port 22 will not stop a determined attacker. It will, however, cut your auth.log noise by 95% and remove enough background scanning that real failed-login alerts become visible again. Pairing the port change with a tight AllowUsers list is the difference between cosmetic hardening and a useful baseline.

What’s happening

cPanel ships OpenSSH listening on 22 by default. cPHulk and CSF/LFD both watch the SSH log, but they fire on every junk attempt; moving the port reduces the volume of failures they have to evaluate. AllowUsers constrains the set of accounts that can authenticate at all — even with a correct password and key, anyone not on that list is rejected before password check.

How to verify

grep -E "^(Port|AllowUsers|PermitRootLogin|PasswordAuth) " /etc/ssh/sshd_config
ss -tnlp | grep sshd
csf -l | grep -E ":(22|2222) "
last -i | head -20
journalctl -u sshd --since "24 hours ago" | grep -c "Failed password"

last -i shows real successful logins by IP, useful to confirm legitimate sources before tightening.

The fix

  1. Pick a port above 1024 that isn’t already used by your stack. Avoid 2222 (overscanned) and any port in your CSF TCP_IN accidentally. We use a random 5-digit port and document it in the runbook.
  2. Edit /etc/ssh/sshd_config:
    • Port <new-port>
    • AllowUsers root user1 user2 — list the operator accounts that need shell. Do not list customer cPanel accounts here unless they specifically need SSH.
    • PermitRootLogin prohibit-password (require keys for root)
    • PasswordAuthentication no once keys are confirmed working
  3. Open the new port in CSF before reloading SSH: add it to TCP_IN and TCP_OUT in csf.conf, csf -r. Verify with csf -l.
  4. Reload sshd with systemctl reload sshd — do not restart from a single open session without a second window already authenticated.
  5. Close port 22 in CSF after 48 hours of clean operation on the new port. Leaving it open with nothing listening is fine, but the goal is to stop the background scanners.
  6. Update WHM > Tweak Settings > SSH Port so the cPanel UI knows the new port and Terminal links work.

Stack Harbor codifies SSH hardening in the takeover runbook under cPanel server management.