2

What is the right way to start a bash script on Oracle Linux?

on a normal Linux server I use ./script.sh

But here is what I got when I do the same on Oracle Linux

[user@server ~]$ ./script.sh
bash: ./script.sh: Permission denied

The permissions are correct

[user@server ~]$ ll script.sh
-rwxr-x--x 1 user oraexpl 317 Jul  4 15:42 script.sh

It works ok if I omit the "/" character

[user@server ~]$ . script.sh
It works

It works ok if I execute it with bash

[user@server ~]$ bash script.sh
It works

In my script, I do have the Shebang /bin/bash

Is this behavior normal?

Thanks for your feedback

Angel115
  • 223

1 Answers1

2

Following up as an answer so this can be accepted and searched. Mounting /home with the noexec option will cause this behavior. The mount option is not prescribed by the CIS benchmark so you may have reason to appeal to the system administrator or the security group. If you have sudo privileges, try removing noexec from the options in /etc/fstab. If something like puppet or chef overrides this, you can use

sudo mount -o remount,exec /home; ./script.sh

as a temporary fix for the problem.

doneal24
  • 5,059
  • That would fix the problem, but also allow users to execute their own binary files. Which my customer don't want. But thanks for your help. now I have the explanation for why I have this behavior. – Angel115 Jul 12 '22 at 10:26
  • 1
    @Angel115 Just an FYI. Similar to using bash ./script you can use /lib64/ld-linux-x86-64.so.2 ./exe to run a binary executable that you normally would be able to execute. Mounting the FS noexec will slow people done but doesn't eliminate the problem. – doneal24 Jul 12 '22 at 12:21