sftp permission denied on chrooted centos

Developer from somewhere

I had the following in my sshd_config:

Match Group myftpgroup
  Allowtcpforwarding no
  Chrootdirectory %h
  Forcecommand internal-sftp

Imagining a user called john, this was the setup:

  • /home was owned by root
  • /home/john was owned by root
  • the files inside john were john’s own files

With all these in place, this was what I received when sftp-ing:

sftp> put README.md
Uploading README.md to /new/README.md
remote open("/new/README.md"): Permission denied

Turns out, it was caused by selinux, and the fix was to run this cmd:

setsebool -P ssh_chroot_rw_homedirs on