21

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?

0

2 Answers 2

24
  • 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.

4
  • 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, 2019 at 21:28
  • 6
    Because you have the user option in there. Jun 25, 2019 at 14:15
  • What is MAC (in this context)? Not MAC address, I presume(?). Jun 25, 2019 at 22:03
  • 3
    Mandatory Access Control
    – Dancrumb
    Jun 25, 2019 at 22:25
0

Well, I found it : it is "log2ram"

As I said, I am using Raspbian on a Raspberry 4, and in order to increase the SD lifetime, I placed the logs on RAM, and here we are.

===
pi@R4:~/logs $ cat /etc/log2ram.conf
[...]
PATH_DISK="/var/log;/home/pi/logs"
===

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .