Skip to content

SFTP key-only access on cPanel — no passwords

How to configure SFTP on cPanel to accept only SSH key authentication, disable passwords entirely for SFTP users, and verify the lockdown holds.

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

  1. Create a dedicated group for SFTP users: groupadd sftp-keyonly. Add target users with usermod -aG sftp-keyonly <user>.
  2. Add the user’s public key to ~/.ssh/authorized_keys with strict permissions: chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys && chown -R <user>:<user> ~/.ssh.
  3. Add a Match block to /etc/ssh/sshd_config:
    Match Group sftp-keyonly
        PasswordAuthentication no
        PubkeyAuthentication yes
        AuthenticationMethods publickey
  4. Validate with sshd -t before reloading. Bad sshd_config blocks all SSH access — including yours.
  5. Reload: systemctl reload sshd. Test both auth paths from a separate session before logging out of the existing root SSH session.
  6. 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.