Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a way to make a directory accessible only to its parent directories. That is, suppose you have two directories, A and B, at the same level in the file hierarchy. Now suppose that you have a directory A' which is a subdirectory of A. I'd like to enforce that A is able to access the contents of A' but B is not.

My problem is that I'd like to use a library (directory A) which builds on top of a legacy version of another library (directory A'). At the same time, I want to be able to use the newest version of this legacy library (directory B). I want to make sure that people aren't somehow using library A and linking against new library B by enforcing that library A must use library A'.

I could just link A against library B, but then I'm risking compatibility.

share|improve this question

migrated from May 31 '10 at 0:50

This question came from our site for professional and enthusiast programmers.

What do you mean when you talk about a directory accessing a directory? Users (their processes) access directories, not other directories. – Anonymouse May 30 '10 at 22:00
Does my edit clarify? – David May 30 '10 at 22:35
You're making the mistake Raymond Chen describes: your problem is trying to keep two versions of a library on one computer, and you've assumed the solution has something to do with restricting access to directories. You'll get much better answers if you ask your real question ("How do I make program A use lib-1.0 but everything else use lib-2.0?") instead. – Stephen Jennings May 31 '10 at 1:43
This shouldn't have been migrated. – Dennis Williamson May 31 '10 at 2:25

Use groups permissions,

suppose you have a group 'foo' and another group 'bar' then

   | |
   | +- A'
  • chgrp -R bar B to set the group permission for subdirectory B.
  • chgrp -R foo A to set the group permission for subdirectory A.

And make certain users be a member of group 'foo' so they will have access to A and its child subdirectories underneath it. Now, users who belong to group 'bar' will have no access to A and its related subdirectories either.

share|improve this answer
I don't want users to have restricted access. There is already a group in use to restrict a subset of users to have access to this directory containing A and B. I'll edit my response to further clarify my problem and goals. – David May 30 '10 at 22:15

What you're asking for doesn't make sense.

Only a running program can access a directory; a directory cannot "access" another directory.

When you launch a program, your user account becomes the owner of that running process (if you run ps -fa, you see your UID on all of your programs)1.

When that process attempts to read a file, the system compares the process owner with the permissions on the file; if the user is allowed read permission, then the read succeeds; otherwise, it fails.

In the case of Program A trying to link against a library, the filesystem permissions on /path/to/LibraryX are compared against the process owner of Program A. Even though the file /path/to/ProgramA has permissions set on it, those aren't considered when the already running instance of Program A attempts to read /path/to/LibraryX. Permissions are only checked against the process owner.

[1] - The exception to this is programs with the setuid bit turned on. When you launch those programs (for example, passwd), then the process owner becomes the file's owner rather than yourself. This is why passwd can edit /etc/shadow even though your user account can't: it always runs as root.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.