SFTP, ChrootDirectory and multiple users

Posted by mdo on Server Fault See other posts from Server Fault or by mdo
Published on 2013-06-11T10:47:20Z Indexed on 2013/06/28 10:23 UTC
Read the original article Hit count: 268

Filed under:
|

I need a setup where I can put the contents of several user folders to a DMZ server from where external clients can download it, protocol SFTP, Linux, OpenSSH. To ease administration we want to use one single user for the upload.

What does work is to define ChrootDirectory /home/sftp/ in sshd_config, set the according ownership and modes and define a home dir in passwd so that the working directory of the user fits. This is my structure:

/home/sftp/uploader/user1/file1.txt
                   /user2/file2.txt

The uploader user can write file1.txt and file2.txt to the corresponding folders and by having the user folders (user1, user2) set to the users' primary group + setting SETGUID on the folders the users are able to even delete the files (which is necessary).

Only problem: because /home/sftp/ is the chroot base dir the users can change updir and see other users' folders, though not being able to change into because of access rights.

Requirement: We want to prevent users to change to /home/sftp/uploader/ and see other users' folders. My requirements are to use SFTP, have one upload user and every user must have write access to his home dir.

Obviously it's not an option to use something like ChrootDirectory %h because every path component of the chroot path needs to have limited access rights, so as far as I understand this does not work.

© Server Fault or respective owner

Related posts about ssh

Related posts about sftp