Debian – bad ownership or modes for chroot directory “/var/www”

chmoddebiansftpsshsshd

I am getting following error in auth.log when trying to connect to site using SFTP.

fatal: bad ownership or modes for chroot directory "/var/www"

ls -ld of this directory shows this:

drwxrwxr-x 4 root sftponly 4096 Aug 12 04:05 /var/www/

As you can see I have given full permission to group sftponly. The user through which I am connecting to SFTP is mysftpuser which is part of sftponly group.

If I do following then I can connect but cannot rename, edit, delete, overwrite any file or folder inside www

sudo chmod 755 /var/www/

Here's my sshd_config setting

Match group sftponly
ChrootDirectory /var/www
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

So in short sudo chmod 755 /var/www/ allows me to connect but only in READ only mode. sudo chmod 775 /var/www/ doesn't even allow me to connect.

How to fix this issue?

Best Answer

Sounds like your permissions are too permissive for SFTP. You will need to create a folder for the user and let him access it with 0700 permissions or even more restrictive than that.

See this question's answer for more info Server Fault Question

Related Question