Password-based SFTP authentication on a public cPanel host is a brute force target. Key-only is the right posture and not difficult to configure — the friction is mostly on the customer side (sending them their key) and operationally (auditing key rotation). The lockdown is in sshd_config, with verification through key-by-key testing.
What’s happening
OpenSSH supports per-user and per-group key-only enforcement via the PasswordAuthentication no directive inside a Match block. Outside the block, the global setting applies — usually yes for the cPanel main account. Within the block (matched on group), no enforces key authentication. The block has to be at the end of sshd_config because Match directives only apply to subsequent statements until another Match.
How to verify
Test before and after:
grep -A 5 'Match Group' /etc/ssh/sshd_config
sshd -t
ssh -o PreferredAuthentications=password <user>@<host>
ssh -o PreferredAuthentications=publickey <user>@<host>
The password test should fail with “Permission denied (publickey)”. The public key test (with the right key) should succeed.
The fix
- Create a dedicated group for SFTP users:
groupadd sftp-keyonly. Add target users withusermod -aG sftp-keyonly <user>. - Add the user’s public key to
~/.ssh/authorized_keyswith strict permissions:chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys && chown -R <user>:<user> ~/.ssh. - Add a Match block to
/etc/ssh/sshd_config:Match Group sftp-keyonly PasswordAuthentication no PubkeyAuthentication yes AuthenticationMethods publickey - Validate with
sshd -tbefore reloading. Bad sshd_config blocks all SSH access — including yours. - Reload:
systemctl reload sshd. Test both auth paths from a separate session before logging out of the existing root SSH session. - Document key rotation. SSH keys do not expire; without policy, the same key from 2018 is still accepted in 2026. Annual rotation is standard, biennial is acceptable for low-risk environments.
Stack Harbor enforces SFTP key-only authentication for every account we manage under cPanel server administration.