Skip to content

Jailed SFTP users on cPanel that actually stay jailed

How to configure SFTP-only, jailed access for end users on cPanel so they cannot wander up the filesystem, and the five tests that prove the jail is working.

A jailed SFTP user should land in their home directory and find that cd / and cd .. do nothing useful. On a default cPanel install, this works for the cPanel account itself. For sub-FTP accounts and for shell accounts handed to clients, the jail is half-configured in ways that only become visible during an audit. Fix it before the audit.

What’s happening

cPanel ships jailshell and the equivalent jailed PAM environment for SSH. Sub-FTP accounts created in cPanel are jailed inside the parent account’s home by Pure-FTPD’s ChrootEveryone yes directive. For SFTP, OpenSSH’s ChrootDirectory setting in /etc/ssh/sshd_config (usually within a Match Group block) does the equivalent — but the chroot target must be owned by root and not writable by anyone else, otherwise sshd refuses to chroot and silently lets the user out.

How to verify

Test from the user’s perspective:

sftp jailed_user@host
> pwd
> cd /
> ls /etc
> get /etc/passwd

A correctly jailed user sees their own home as /, gets a permission error on cd /etc, and cannot fetch /etc/passwd. From the server side:

grep -A 5 'Match Group sftponly' /etc/ssh/sshd_config
stat -c '%U %a' /home/jailed_user
journalctl -u sshd --since '10 min ago' | grep -i chroot

If sshd logs “bad ownership or modes for chroot directory” you have a silent fall-back to non-jailed access.

The fix

  1. Create a dedicated group, e.g. sftponly, and add the user to it. Set their shell to /sbin/nologin so only SFTP works.
  2. In sshd_config, add a Match Group sftponly block with ChrootDirectory /home/%u, ForceCommand internal-sftp, AllowTcpForwarding no, X11Forwarding no. Reload with systemctl reload sshd and verify with sshd -t first.
  3. The chroot directory itself must be root:root 755. The user’s writable content goes in a subdirectory they own — typically /home/<user>/files. This trips people up: the home appears unwritable to the user, by design.
  4. For cPanel sub-FTP accounts, confirm ChrootEveryone yes in /etc/pure-ftpd.conf and restart pure-ftpd. There is no per-user override for this in pure-ftpd, which is the right behavior.
  5. After changes, run the five-step verification above for at least one user per role. A passing audit is two minutes of testing, not a config diff.

Stack Harbor enforces jailed access by default on every environment we manage.