Search code examples
linuxcentosrhel

Link directories in CentOS 7


Hi I am on a CentOS server, I have a user called 'theowner' so he has his folder under /home/theowner

In other hand I have 2 folders, f1 and f2 under /home/myprojects/src and I just want that these folders appears under /home/theowner but I don't want to move the folder I want is to link that 2 folders to /home/theowner. It's for c9 workspace, and I just want to allow theowner to access that folders directly when he logins. Thanks!


Solution

  • @Lubomir already gave a symlink solution.

    However, his solution will require that theowner has at least a read-execute permission to all the parent directories of /home/myprojects/src/f1 and /home/myprojects/src/f2.

    In most situation, you don't want theowner to see anything outside of /home/myprojects/src/f1 and /home/myprojects/src/f2.

    Bind mount to the rescue.

    As theowner create the following directories.

    $ mkdir f1 f2
    

    As root, mount the source directories to the target directories.

    # mount -o bind /home/myprojects/src/f1 /home/theowner/f1
    # mount -o bind /home/myprojects/src/f2 /home/theowner/f2
    

    If you want it to persist across reboots, add the 2 entries in /etc/fstab

    /home/myprojects/src/f1  /home/theowner/f1  auto  auto,bind  0 0
    /home/myprojects/src/f2  /home/theowner/f2  auto  auto,bind  0 0
    

    With this solution, theowner doesn't need to have access to the parent directories of /home/myprojects/src/f1 and /home/myprojects/src/f2.