Running sh script: «Permission denied» despite the executable bit and root rights

Maybe your file system is mounted with noexec option set, so you can not run any executable files. From mount documentation:

noexec

Do not allow direct execution of any binaries on the mounted filesystem. (Until recently it was possible to run binaries anyway using a command like /lib/ld*.so /mnt/binary. This trick fails since Linux 2.4.25 / 2.6.0.)

Try:

mount | grep noexec

Then check if your file system is listed in output.

If yes, you can solve this problem, by re-mounting file system with exec option:

mount -o remount,exec filesystem

bash -x ./filename.filetype should work. It worked for me when I got permission denied as a root user.


My solution to this problem is to use source. I was on a storage volume of very important data. This volume is mounted as noexec. I have a simple shell script that is executable but got permission problem.

./fixsamplesheet.sh # this guy is executable
-bash: ./fixsamplesheet.sh: Permission denied

source fixsamplesheet.sh # worked fine

Only tested on my Ubuntu.