-2

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

1

/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.