Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symbolic links to folders whose parent directory has no execute permission

Tags:

linux

symlink

I am trying to do a soft link from one directory to another, the directory I am trying to access I have read and execute. However, its parent directory I do NOT have execute permissions.

Is there a way to do a soft link, to my desired directory without giving me execute permission to the parent directory?

Below is the code I used:

ln -s /home/dir1/dir2/desired_directory symbolic_link_name

the link just comes up as red with grey background.

Thank you.

like image 250
user2891652 Avatar asked Sep 03 '25 03:09

user2891652


2 Answers

Although this is not possible with symlinks, you could do it with mount --bind. Note that if the whole point is to circumvent security, then this is probably a very bad idea.

Your command would be

mount --bind /home/dir1/dir2/desired_directory mount_dir

There are a few issues to be aware of:

  • The target directory mount_dir must exist before (same as any mount point)
  • Root access is required to execute the mount commmand
  • The created "link" will not persist after a reboot unless a corresponding line is added to /etc/fstab
  • If the origin directory contains mounted file systems, these will not be transferred to the target. The mount points will appear as empty directories.
  • Using mount --bind may be considered bad practice because most programs are not aware that the "link" is not a standard directory. For instance it allows the creation of loops in the directory tree which make any tree parsing application (think "ls -R") enter a possibly infinite loop.
  • It may be hazardous when combined with recursive delete operations. See for instance Yet another warning about mount --bind and rm -rf.
like image 81
kragol Avatar answered Sep 05 '25 22:09

kragol


Symbolic links are not a way to circumvent permissions set on their targets. No, there is no way to do what you want. If it was possible it would be a serious security issue.

like image 33
Nikos C. Avatar answered Sep 06 '25 00:09

Nikos C.