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
- Pick a port above 1024 that isn’t already used by your stack. Avoid 2222 (overscanned) and any port in your CSF
TCP_INaccidentally. We use a random 5-digit port and document it in the runbook. - 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 noonce keys are confirmed working
- Open the new port in CSF before reloading SSH: add it to
TCP_INandTCP_OUTincsf.conf,csf -r. Verify withcsf -l. - Reload sshd with
systemctl reload sshd— do not restart from a single open session without a second window already authenticated. - 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.
- 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.