I created a script, and I want it to be rwx only by root. All other can only x. What I have now

[root@localhost /]# chmod 755 scripts/ -v
mode of 'scripts/' retained as 0755 (rwxr-xr-x)
[root@localhost /]# chmod 711 scripts/macchange -v
mode of 'scripts/macchange' retained as 0711 (rwx--x--x)

And I think all is good here. If I go with my user I can read the folder content, but not the files. But when I'm trying to exec the script this is what I get

[iron@localhost /]$ ./scripts/macchange 
/bin/bash: ./scripts/macchange: Permission denied

What am I doing wrong? If I give my user permission to read it suddenly works.

Explanation why it's different then the possible duplicate: I didn't realize bash needs to read the file to execute it. I thought it's an issue of folder to file permissions.

  • 1
    How is it going to execute it, if it can't read it? – Hunter.S.Thompson Sep 9 '17 at 19:40
  • What's the purpose of 1 in chmod then? I thought that's the whole idea. User cannot read the information, but can execute – Alex Ironside Sep 9 '17 at 19:41

/bin/bash will not be allowed to read the contents of the file to execute.

You will have to enable read permissions.

chmod 751 /scripts/macchange ##If you only want the user's of the same group to access the file.
| improve this answer | |

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