Cannot execute script while its permission is 'x'
I have a script in the current directory, however, given that:
- the permission is
-rwxr-xr-x
- the script has a shebang
#!/bin/bash
at the top of the file - my shell is
/bin/bash
- I can execute it using
bash script.sh
I cannot execute it using ./script.sh
. It gives me:
bash: ./script.sh: Permission denied
Why is this happening and what is the solution?
Solution 1:
The execution is not allowed because the file is on a filesystem mounted with the "noexec" option. Use
findmnt -u -T .
to find out if that's the case. If you have root privileges,mount -o remount,exec <dir>
should remove this option.The execution is not allowed by MAC policies (SELinux, SMACK, possibly AppArmor). Check the system logs, starting with
journalctl -n 100
anddmesg
. Bypassing this (if you're the administrator) depends on which MAC system is actually in use.