I created the user MY_USER. Set his home dir to /var/www/RESTRICTED_DIR, which is the path he should be restricted to. Then I edited sshd_config and set:
Match user MY_USER
ChrootDirectory /var/www/RESTRICTED_DIR
Then I restarted ssh. Made MY_USER owner (and group owner) of RESTRICTED_DIR, and chmodded it to 755. I get
Accepted password for MY_USER
session opened for user MY_USER by (uid=0)
fatal: bad ownership or modes for chroot directory component "/var/www/RESTRICTED_DIR"
pam_unix(sshd:session): session closed for user MY_USER
If I removed the 2 lines from sshd_config the user can login successfully. Of course it can access all the server though. What's the problem? I even tried to chown RESTRICTED_DIR to root (as I read somewhere that someone solved this same problem doing it). No luck..
/,/var,/var/www, and/var/www/RESTRICTED_DIRmust all meet the security requirements above). It is a true chroot (review the man page) - your user's home directory needs to exist within the chroot, as must/bin& all the other things your user will need... – voretaq7 Mar 28 '14 at 00:03/var/www/RESTRICTED_DIRhad chmod0775. I set0755and all errors went away. Problem is it didn't login. I solved changingSubsysteminsshd_configtoSubsystem sftp internal-sftp. Now: last problem: chrooted user doesn't have write access inRESTRICTED_DIR..!! – MultiformeIngegno Mar 30 '14 at 18:00/var/log/auth.login Ubuntu or/var/log/securein RHEL. – Devy Sep 08 '14 at 19:07sudo chown root:root -R /path/to/home; sudo chmod 755 -R /path/to/home– mmell Jan 15 '15 at 23:32/var/wwwpath directly, which might break apache, you'd be far better off putting your sftp directory in another path, then using URL mapping in Apache to point to the other directory. Check the documentation here https://httpd.apache.org/docs/2.4/urlmapping.html underFiles Outside DocumentRoot– Daniel Sep 03 '16 at 02:58setfacl -Rd -m 'u:MY_USER:rwx' /var/www/RESTRICTED_DIR && setfacl -R -m 'u:MY_USER:rwx' /var/www/RESTRICTED_DIR– Felipe Alcacibar Sep 06 '16 at 02:31/var/www/RESTRICTED_DIR/<youruser>– Holger Böhnke Apr 03 '22 at 09:01