Disabling SSH password authentication is the single change with the highest return per minute on a cPanel server. It also has the highest blast radius if done sloppily — one bad authorized_keys permission and the operator team is locked out at 02:00. Here is the careful version.
What’s happening
cPanel allows per-account SSH if Jail Shell or Normal Shell is granted in WHM > Manage Shell Access. Each cPanel user has ~/.ssh/authorized_keys separately from root. Disabling PasswordAuthentication in sshd_config is global — it applies to root, operator accounts, and any cPanel user with shell. If even one operator account has not yet imported a working key, that account is now locked out.
How to verify
grep -E "^(PasswordAuthentication|PubkeyAuthentication|ChallengeResponseAuthentication) " /etc/ssh/sshd_config
for u in $(awk -F: '$3>=500 {print $1}' /etc/passwd); do \
test -f /home/$u/.ssh/authorized_keys && echo "$u has keys"; done
stat -c "%a %U %n" /home/*/.ssh/authorized_keys 2>/dev/null
ssh -i ~/.ssh/your_key -o PreferredAuthentications=publickey -o PasswordAuthentication=no -p <port> root@host whoami
The dry-run ssh line proves key-only login works before you disable passwords.
The fix
- Inventory operator accounts. List every account that should retain SSH access and confirm each has a working public key in
authorized_keys. - Confirm permissions:
~/.sshshould be700,authorized_keysshould be600, owned by the user. Thefor u inloop above will spot stragglers. - For cPanel customers needing SSH: have them paste a public key into cPanel > SSH Access > Manage SSH Keys themselves, then authorize the key. Do not paste customer keys for them — chain-of-custody matters.
- Test key-only auth from a fresh session with the explicit
PreferredAuthentications=publickey -o PasswordAuthentication=noflags. If that fails, you are not ready. - Edit
sshd_config:PasswordAuthentication noChallengeResponseAuthentication noPubkeyAuthentication yesKbdInteractiveAuthentication no
- Reload sshd from a second already-authenticated session:
systemctl reload sshd. Keep that second session open for 15 minutes while you verify. - Document the lockout-recovery path: console access via the host provider, single-user mode, key reset procedure. Untested recovery is unrecovery.
Stack Harbor migrates fleets to key-only SSH and maintains the operator key inventory under cPanel/WHM management.