Interview Prep/Shell Scripting/Troubleshooting: tools, portability, permissions and environment

A bootstrap step `curl -fsSL "$URL" -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh` fails with `bash: /tmp/install.sh: Permission denied`, despite the `chmod`.

IntermediateTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer

Likely causes → /tmp is mounted with noexec (CIS hardening benchmarks require it), so the kernel refuses to execute any file there regardless of its mode.

Diagnose →

findmnt -no OPTIONS /tmp        # rw,nosuid,nodev,noexec,...
ls -l /tmp/install.sh           # mode is fine

Fix → Run it through the interpreter, or download to a location meant for executables after verifying it:

bash /tmp/install.sh                                     # the file is read, not executed
echo "${EXPECTED_SHA256}  /tmp/install.sh" | sha256sum -c -

Prevent → Do not depend on executing from /tmp; verify checksums of anything downloaded before running it, and test bootstrap scripts on hardened images.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Troubleshooting: tools, portability, permissions and environment