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
- Create a dedicated group, e.g.
sftponly, and add the user to it. Set their shell to/sbin/nologinso only SFTP works. - In
sshd_config, add aMatch Group sftponlyblock withChrootDirectory /home/%u,ForceCommand internal-sftp,AllowTcpForwarding no,X11Forwarding no. Reload withsystemctl reload sshdand verify withsshd -tfirst. - 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. - For cPanel sub-FTP accounts, confirm
ChrootEveryone yesin/etc/pure-ftpd.confand restartpure-ftpd. There is no per-user override for this in pure-ftpd, which is the right behavior. - 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.