To allow access to a directory by a chrooted linux user (which lies outside the user’s dir tree) use “mount –bind sourceDirPath targetDirPath”
Mounting a directory means creating a link to the contents of the directory anywhere on the volume or even another volume. For example, if you have a D:/ and a C:/, one can create a link to the D:/ in the C:/ and access the contents of the D:/ as if it were a folder within the C:/
Using the bind –mount however, replicates one directory structure within the other (and not just created a link). Any changes made in one directory get reflected in the other directory immediately.
One use case: You are working on a project and want to give access to two different directories to a chrooted linux user. Furthermore, neither of the two directories are within the home directory of the chrooted user. This would not possible since the home directory of the chrooted user does not contain either of the dirs (that is the whole point of chrooting a user!).
Using “mount –bind” the root user can allow the chrooted user access to any number of dirs which are outside the home dir of this user.
To allow access to the outside dir, the root user must first create an empty dir under the chrooted user’s home dir with the same name and then bind the empty dir to the outside dir.
For example, assume the chrooted user’s home dir is /var/www/chr_dir and the root user wants the chrooted user to have access to /var/www/someDir.
sudo mkdir /var/www/chr_dir/someDir
mount --bind /var/www/someDir /var/www/chr_dir/someDir
Now when the chrooted user logs into his account (via FTP or SSH or otherwise); he will see someDir as one the directories with all the same contents as they are under /var/www/someDir.
To remove the user’s access to the directory, use the ‘umount’ command:
sudo umount /var/www/chr_dir/someDir
This will “unmount” the directory from the user’s home directory and the user will not have access to the contents of the outside directory anymore. Do note that the dir ‘someDir’ will still appear in the user’s account. Only its contents will get removed. To remove the actual directory itself, remove it using the “rm” command.
Source: https://askubuntu.com/questions/780406/is-mount-bind-dir1-dir2-an-alternative-for-hard-links-for-directories
1,754 total views, 2 views today