Linux does not execute a file because of its name or extension - it executes it because the file has the execute permission bit, lives on a filesystem that allows execution, and starts with a valid shebang line with Unix line endings. ./script.sh: Permission denied maps to the first two; a cousin error, bad interpreter: No such file or directory, maps to the third - usually a script edited on Windows with CRLF line endings. Fix the one you actually have.
X The file exists - ls shows it in the current folder
X Reading it works fine: cat script.sh shows the contents
X It was just downloaded, copied from a USB drive, or written on Windows
X Other programs run normally from your home folder
NOT EXECUTABLE No execute bit, a noexec mount, or CRLF endings - three different causes, three one-line fixes.
The fingerprint of this problem: the file is readable but not executable - Linux separates those two permissions on purpose.
cat script.sh or less script.sh. The execute bit is a safety gate, not just a nuisance.New files are created without execute permission by design. Granting it is the normal, intended fix. ⭐
ls -l script.sh - a line starting -rw-r--r-- has no x anywhere, confirming the cause.chmod +x script.sh./script.sh - the ./ matters, it tells bash to run the file in the current folder rather than searching PATH.ls -l script.sh again - the permissions should now show x, like -rwxr-xr-x.Calling the interpreter yourself bypasses the execute-bit requirement for reading the file as a script - useful on shared or locked-down systems.
bash script.sh (or sh script.sh only if the script is written for sh - bash is the safer default for .sh files from tutorials).USB drives and some shared mounts are mounted with noexec, which blocks execution even when the file has its x bit - the signature is Permission denied that survives chmod +x.
findmnt -no OPTIONS /media/$USER/USBNAME (use your mount path) and look for noexec in the options.cp script.sh ~/ && chmod +x ~/script.sh && ~/script.shIf the message is really bad interpreter: No such file or directory, the shebang line ends with a hidden carriage return from Windows editing - bash is looking for an interpreter whose name ends in that invisible character.
file script.sh will say with CRLF line terminators when this is the cause.dos2unix script.sh (install it with sudo apt install dos2unix if missing). A built-in alternative: sed -i 's/\r$//' script.sh#!/bin/bash, keep the execute bit, and run ./script.sh again.Rarely, the file is owned in a way that leaves you without execute rights even as the apparent owner of the folder.
ls -l script.sh and namei -l ./script.sh - every folder on the path needs x for you to reach and run the file.sudo chown $USER:$USER script.sh, then chmod +x script.sh.chmod 777 as a habit - it makes the file writable by every account on the machine when chmod +x or chmod u+x is all you need. Do not run a downloaded script with sudo to get past a permission error before reading it - sudo raises the damage a bad script can do, it does not fix permissions. And do not disable noexec mounts on shared systems to run one file; copy the file to your home folder instead.Every week: Windows problems, hidden tools and full setup guides, explained step by step.
Subscribe on YouTubeBecause the file does not have the execute permission bit. Linux separates read and execute permissions: a downloaded or newly created script is readable but not executable by design. Fix it with chmod +x script.sh, then run ./script.sh again.
chmod +x adds only the execute bit, keeping the rest of the permissions as they are. chmod 777 grants read, write and execute to everyone - owner, group and all other users - which is unnecessary and unsafe for a script. Use chmod +x, or chmod u+x to limit it to yourself.
The filesystem is probably mounted with the noexec option, common on USB drives and some shared mounts. noexec blocks execution regardless of file permissions. Copy the script to your home folder, chmod +x it there, and run it from there - or run it as bash script.sh, which only needs read permission.
The script's first line (the shebang, such as #!/bin/bash) ends with a Windows carriage return, so Linux looks for an interpreter with a corrupted name. The file command shows CRLF line terminators in this case. Fix it with dos2unix script.sh, then run it again.
Yes - pass it to the interpreter: bash script.sh. The interpreter only needs to read the file, so no execute bit is required. This works for shell and other text scripts, but not for compiled binary programs, and it ignores the script's shebang, so name the correct interpreter yourself.