For basic security reasons, FTP daemons don’t let you access folders that are symlinks (aka shortcuts) to folders that are outside of your jailed root, when you have chroot jailing enabled. This is standard practice for most shared FTP servers. So for instance my FTP session is limited to /home/sherl0k and all its subdirectories. I recently added a second harddrive to my server, and I wanted to access that drive with two major conditions: 1) not mounting the drive in a folder that resides in my /home, and b) giving me access to the contents without requiring a second FTP login. I also wasn’t going to turn off chroot.
So as I said, a symlink is not possible here. Doing a ln -s /second/dreamcast ./dreamcast from inside my home, and then accessing it via FTP, would yield an error: 550 Failed to open file.
So what’s a sysadmin to do?
Oh, the joys of the mount command. Believe it or not, it’s possible to mount a folder and/or filesystem in two places at once. Mind you making changes in one place will yield those same exact changes in the other, so doing editing in both places at once would yield some issues. But for my uses, this would never happen. I suppose this would also apply to normal symlinks.
Lo and behold, the code to rule them all: mount --bind -rw /second/dreamcast/ ./dreamcast
The drive was originally mounted as /second, with the dreamcast directory owned by my user account. I can now "bind" the folder anywhere on the filesystem – in this case inside my home directory – and have full access to it via FTP. No symlink involved.
This is very very handy for me at work, thanks sherl0k.
Comment by Corey — May 12, 2009 @ 7:07 am
Or you could just SCP.
Comment by phuzion — June 17, 2010 @ 4:46 pm