I need to setup some users to access our server. I thought the most secure way to allow them access was to setup a chroot'ed jail for them to log into.

But I need them to access a few select directories that are outside the chroot'ed environment. Apparently I can't use symlinks for this. What is the best approach? Can a chroot'ed environment not be used for this purpose?

  • 3
    Isn't the whole point of a chroot'ed environment to prevent access to files outside of the chroot? So, any way around that would be a bug? – Andrew Barber Nov 15 '10 at 23:46
  • Maybe you could suggest a better way for me to set this up then? – Jake Wilson Nov 15 '10 at 23:51

This is a place where a bind mount will do what you want.

  • 5
    A bind mount would likely be the best way out of this hole. "mount -o bind /dir/outside/chroot /dir/inside/chroot" To survive a reboot add "/dir/inside/chroot /dir/outside/chroot none bind 0 0" to your /etc/fstab file. – Rik Schneider Nov 16 '10 at 3:18

If it's on the same filesystem and it's individual files, hardlinks will work.

Softlinks will not work: the main purpose of a chroot'ed jail is that users can't get out to access files that aren't inside there.

You can use cp -lr to duplicate a directory tree with each file being a hardlink to the same underlying file, but that won't immediately pick up renames/moves, new files or deletes.

I think @SvenW has the best idea: move the directory into the chroot area and make the current location a symlink to the version inside the chroot.

  • I get "Invalid cross-device link". The files are on a different internal hdd. Guess that's not gonna work. – Jake Wilson Nov 15 '10 at 23:52
  • 1
    Maybe you could move the files into the required file system and then maybe use symlinks for other non-chrooted users? – Sven Nov 16 '10 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.