Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I ran in to an interesting issue with mounting that doesn't make any sense to me. Basically I have setup a chroot environment for SFTP users, they each have a chroot directory with a format of "/sftp/username/files". There is one chroot user called "downloads" whose directory will contain a bunch of files that are for downloading. The "downloads" user can upload/download files, but I also want to share the download user directory "/sftp/downloads/files" with all other users, giving them read-only access to that directory. From my research, it seemed like the way to do this is by using the mount --bind command as follows:

mount --bind /sftp/downloads/files /sftp/user1/files
mount --bind /sftp/downloads/files /sftp/user2/files

Before I ran the mount command, the following directory ownerships were in place, having "/sftp/username" being owned by root and the "/sftp/username/files" directory being owned by the respective sftp user who is part of a group called "sftpusers".

Here is a "ll" command on the /sftp directory:

drwxr-xr-x  3 root root 4096 Mar 24 15:20 downloads
drwxr-xr-x  3 root root 4096 Mar 24 08:00 user1
drwxr-xr-x  3 root root 4096 Mar 24 08:00 user2

And here are "ll" commands on each of the /sftp/username directories:

ll /sftp/downloads
drwxr-xr-x 3 downloads sftpusers 4096 Mar 25 11:15 files

ll /sftp/user1
drwxr-xr-x 3 user1 sftpusers 4096 Mar 25 11:15 files

ll /sftp/user2
drwxr-xr-x 3 user2 sftpusers 4096 Mar 25 11:15 files

Now, this is what happens to the directory ownerships after I run the mount commands that I listed earlier:

ll /sftp/downloads
drwxr-xr-x 3 user1 sftpusers 4096 Mar 25 11:15 files

ll /sftp/user1
drwxr-xr-x 3 user2 sftpusers 4096 Mar 25 11:15 files

ll /sftp/user2
drwxr-xr-x 3 downloads sftpusers 4096 Mar 25 11:15 files

It's like the ownership of each of the directories swapped with each other. I am able to go change the ownership of the "downloads" /files directory, back to being owned by downloads, but then when I go to fix the ownership of "/sftp/user1/files", the /sftp/downloads/files ownership will again change to being owned by user1. I cannot figure out why this would be happening and I am at a loss for what to do.

share|improve this question
    
You should mount the shared directory into a user-specific subdirectory in each respective chroot-jail instead of just bind-mounting it directly to each chroot-jail. –  Sami Laine Mar 26 at 7:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.