Skip to content

Switching cPanel SSH to key-only authentication without breaking access

A safe path from password-and-key SSH to keys-only on a cPanel server, including the cPanel-specific gotchas around per-user authorized_keys.

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

  1. Inventory operator accounts. List every account that should retain SSH access and confirm each has a working public key in authorized_keys.
  2. Confirm permissions: ~/.ssh should be 700, authorized_keys should be 600, owned by the user. The for u in loop above will spot stragglers.
  3. 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.
  4. Test key-only auth from a fresh session with the explicit PreferredAuthentications=publickey -o PasswordAuthentication=no flags. If that fails, you are not ready.
  5. Edit sshd_config:
    • PasswordAuthentication no
    • ChallengeResponseAuthentication no
    • PubkeyAuthentication yes
    • KbdInteractiveAuthentication no
  6. Reload sshd from a second already-authenticated session: systemctl reload sshd. Keep that second session open for 15 minutes while you verify.
  7. 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.