3

Background

I am working on a RHEL 5 cluster. I want my Fortran program to read the file /home/bob/inputs/input_1

  1. I asked Bob to give me permission to read all contents of inputs:

    [bob@server]$ chmod -R a+r /home/bob/inputs/*
    
  2. I linked these to a shared directory:

    [david@server]$ ln -s /home/bob/inputs/ /home/share/inputs/
    
  3. My (Fortran) program tried to read /home/share/inputs/input_1 and said:

    File /home/share/inputs/input_1 not found!
    
  4. I tried to locate the file myself (in the process, bob gave a+rwx permissions):

    [david@server]$ls -ltrh /home/share/inputs/input_1
    lrwxrwxrwx 1 bob bob 33 Oct 25 15:42 /home/share/inputs/input_1 -> /home/bob/inputs/input_1
    

    From this, I concluded that a) inputs_1 exists and b) all users have rwx permission.

  5. I tried to read it:

    [david@server]$ more /home/share/inputs/input_1 
    /home/share/inputs/input_1: No such file or directory
    

    And am told that it does not exist.

  6. I look for the target file /home/bob/inputs/input_1 but am denied permission.

    [david@server]$ls -ltrh /home/bob/inputs/input_1
    ls: /home/bob/inputs/input_1 Permission denied
    
  7. Something bizzare happens if I ls the directory contents:

    [david@server]$ls -ltrh /home/bob/inputs/
    ?--------- ? ? ? ?            ? input_1
    ?--------- ? ? ? ?            ? input_2
    ?--------- ? ? ? ?            ? input_3
    ... (n-4 lines omitted) 
    ?--------- ? ? ? ?            ? input_n
    

    although if bob does this, he gets:

    -rwxrwxrwx 1 bob bob  269 May 24  input_1
    ... (n-2 lines omitted) 
    -rwxrwxrwx 1 bob bob 2.0K Jan 19  input_n
    

Questions:

  • Is there a simple explanation for this apparently (to me) inconsistent behavior?
  • Where do I go from here?

2 Answers2

4

You need execute permissions on /home/bob/inputs. You can set it with:

chmod a+x /home/bob/inputs
Michael Mrozek
  • 93,103
  • 40
  • 240
  • 233
Chris Card
  • 2,292
  • 1
    Getting bob to chmod a+rwx /home/bob/inputs was the solution. – David LeBauer Oct 26 '12 at 22:04
  • 2
    You don't need w. – Jim Paris Oct 26 '12 at 22:08
  • 2
    You don't need r either. – kubanczyk Oct 26 '12 at 22:48
  • You will need r permission if you want to access files in this directory, or sub directories below it. – Hai Vu Oct 29 '12 at 13:56
  • @HaiVu On the contrary - you need x (execute) permission to be able to access files in that directory - the r permission is needed to able to list the contents of the directory itself (just the file names). To see the permissions of each of the files, you need x on the directory - that is why there are question marks in OP's ls output. – rozcietrzewiacz Oct 30 '12 at 11:58
3

Run ls -ld /home/bob/inputs/. I think you'll find that bob gave you read permission on the directory, but not execute permission, i.e. something like drwxr--r--. On a directory, read permission lets you see the list of files while execute permission lets you access files in the directory. There are rare circumstances where it's useful to make a directory executable and not readable; the contrary is pretty useless. Almost all the time, a directory should either be accessible (readable and executable) or not accessible (neither readable nor executable).

See Why do directories need the executable (X) permission to be opened? for more explanations.

Remedy: ask bob to run chmod a+rx ~/inputs.