18

I have a script in the current directory, however, given that:

  1. the permission is -rwxr-xr-x
  2. the script has a shebang #!/bin/bash at the top of the file
  3. my shell is /bin/bash
  4. 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?

20
  • 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 and dmesg. Bypassing this (if you're the administrator) depends on which MAC system is actually in use.

  • 3
    Thank you, in my case it is noexec. I got confused, I have this disk mount as /home ext4 auto,exec,rw,async,user 0 2 in /etc/fstab, why is it noexec? – Henry Jun 24 at 21:28
  • 6
    Because you have the user option in there. – grawity Jun 25 at 14:15
  • What is MAC (in this context)? Not MAC address, I presume(?). – Peter Mortensen Jun 25 at 22:03
  • 3
    Mandatory Access Control – Dancrumb Jun 25 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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