Technical Anshu
Tutorials Blog

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.

Terminal · Bash
$ ./script.sh
bash: ./script.sh: Permission denied

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.

Before you start: only make a script executable if you know where it came from and what it does - read it first with cat script.sh or less script.sh. The execute bit is a safety gate, not just a nuisance.
1

Add the Execute Permission With chmod +x ⭐

New files are created without execute permission by design. Granting it is the normal, intended fix. ⭐

  1. Check the current permissions: ls -l script.sh - a line starting -rw-r--r-- has no x anywhere, confirming the cause.
  2. Grant execute for yourself: chmod +x script.sh
  3. Run it: ./script.sh - the ./ matters, it tells bash to run the file in the current folder rather than searching PATH.
  4. Verify the change with ls -l script.sh again - the permissions should now show x, like -rwxr-xr-x.
2

Run It With bash Directly When You Cannot or Should Not chmod

Calling the interpreter yourself bypasses the execute-bit requirement for reading the file as a script - useful on shared or locked-down systems.

  1. Run: 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).
  2. This also bypasses the shebang line, so if the script needs a specific interpreter, name that interpreter explicitly.
  3. Note the limit: this does not help for compiled binaries, only for text scripts an interpreter can read.
3

If the Folder Is Mounted noexec, Move the Script or Remount Knowingly

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.

  1. Check the mount: findmnt -no OPTIONS /media/$USER/USBNAME (use your mount path) and look for noexec in the options.
  2. Simplest fix: copy the script to your home folder, chmod it there, and run it from there: cp script.sh ~/ && chmod +x ~/script.sh && ~/script.sh
  3. Do not remount system partitions without noexec as a casual fix - that option is often a deliberate security policy, especially on shared machines.
4

Fix Windows Line Endings When the Error Mentions a Bad Interpreter

If 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.

  1. Check the endings: file script.sh will say with CRLF line terminators when this is the cause.
  2. Convert in place: dos2unix script.sh (install it with sudo apt install dos2unix if missing). A built-in alternative: sed -i 's/\r$//' script.sh
  3. Make sure the first line is a clean shebang such as #!/bin/bash, keep the execute bit, and run ./script.sh again.
5

Check Ownership and ACLs on Stubborn Cases

Rarely, the file is owned in a way that leaves you without execute rights even as the apparent owner of the folder.

  1. Run ls -l script.sh and namei -l ./script.sh - every folder on the path needs x for you to reach and run the file.
  2. If the file is owned by root from an earlier sudo copy, take ownership or re-copy it as your user: sudo chown $USER:$USER script.sh, then chmod +x script.sh.
Do not do this: do not use 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.

More PC Fixes on Technical Anshu

Every week: Windows problems, hidden tools and full setup guides, explained step by step.

Subscribe on YouTube

Frequently Asked Questions

Why does bash say Permission denied when I run ./script.sh?

Because 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.

What is the difference between chmod +x and chmod 777?

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.

chmod +x worked but it still says Permission denied. Why?

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.

What does bad interpreter No such file or directory mean for a script?

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.

Can I run a script without chmod +x?

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.

Guide by Technical Anshu · Problem collected from Linux forum and Ask Ubuntu user reports of Permission denied when running shell scripts; solution written in original words and verified against the Bash and chmod man pages and Ubuntu documentation on file permissions and mount options, verified on 11 November 2026. No matching long video exists on the channel for this exact fix, so this blog has no video section - the topic joins the fresh video-topic bank. No Shorts are linked in this blog.