Problem
I have created a chroot SFTP user with home directory /incoming, Now I have to share the files contained in the folder /home/documents/pdf. Documents in directory /home/documents/pdf are continuously increasing and I have to share these documents with SFTP users in real-time.
To share the documents in directory /home/documents/pdf i have created a symbolic link ln -s /home/documents/pdf /home/sftp/sftp_user1/incoming/pdf. But when FTPS user tries to access this directory he found this as a file named pdf in his home directory /incoming while I was able to access the files through the symbolic link on the SFTP server.
This has happened because, after the chroot operation, the file system has no knowledge of any data outside of the chroot directory. This lack of knowledge breaks the symlink.
Solution
Use the bind mount to remove the above issue. Bind mount is mounting a path into another path instead of mounting a device with a file system on a particular path.
[user@dbappweb.com ~]$ sudo mount -o bind /home/documents/pdf /home/sftp/sftp_user1/incoming/pdf
[user@dbappweb.com ~]$ sudo mount |grep pdf /home/documents/pdf on /home/sftp/sftp_user1/incoming/pdf type none (rw,bind)
Make the following entry in fstab to automount in case of a system reboot
[user@dbappweb.com ~]$ sudo cat /etc/fstab . . /home/documents/pdf /home/sftp/sftp_user1/incoming/pdf none bind 0 0
Now SFTP user can access the files under directory /home/documents/pdf (on the servers) in his home directory /incoming/pdf
sftp> pwd Remote working directory: /incoming sftp> ls pdf sftp>cd pdf sftp> ls file1.pdf file2.pdf ...............
Last Updated: August 09, 2020
Note: When you use the bind option of the mount command, you must be sure that the file systems are mounted in the correct order. In the following example, the /var/log directory must be mounted before executing the bind mount on the /tmp directory:
# mount --bind /var/log /tmp