---
title: "bash: ./script.sh: Permission denied"
description: "Why running a shell script gives Permission denied, and how to fix it with chmod +x, a correct shebang line, or by working around a noexec mount."
url: https://www.danny.engineering/answer/bash/bash-scriptsh-permission-denied
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:25:00.000Z
tags: ["Bash"]
---

# bash: ./script.sh: Permission denied

## The short answer


Your script file is missing the execute permission. Unix-like systems will only run a file directly (as `./script.sh`) if it is marked executable for your user. Add the permission with `chmod` and run it again.


```bash
chmod +x script.sh
./script.sh
```


If that still fails, check the first line of the script (the shebang) and whether the file lives on a filesystem mounted with `noexec`.


## Why it happens


When you type `./script.sh`, you are asking the kernel to execute the file. Before it does, it checks the file's permission bits. Every file has read, write and execute bits for three groups: the owner, the group, and everyone else. You can see them with `ls -l`:


```bash
$ ls -l script.sh
-rw-r--r--  1 dan  staff  120 27 Nov 10:12 script.sh
```


That `-rw-r--r--` means the owner can read and write, everyone else can read, and nobody can execute. New files created by editors, `touch`, `git clone` on some setups, or downloads usually start without the execute bit, so the kernel refuses with `Permission denied`.


There are two other common causes that produce the same message or a close cousin:

- **A broken shebang.** The first line, such as `#!/usr/bin/env bash`, tells the kernel which interpreter to run. If it points at a path that does not exist you usually see `bad interpreter: No such file or directory` instead, but a shebang pointing at a file that is not executable gives `Permission denied`.
- **A** **`noexec`** **mount.** Some systems mount `/tmp`, home directories on shared machines, USB drives or container volumes with the `noexec` option. Nothing on that filesystem can be executed directly, no matter what `chmod` says.

## How to fix it


### Add the execute bit


This is the fix nine times out of ten.


```bash
# Executable for everyone who can read it
chmod +x script.sh

# Or only for the owner
chmod u+x script.sh
```


If the script is in a Git repository, record the permission in Git so it survives a fresh clone for your teammates and CI:


```bash
git update-index --chmod=+x script.sh
git commit -m "Make script.sh executable"
```


### Check the shebang line


Make sure the very first line of the file is a valid shebang, with no blank line or spaces before it:


```bash
#!/usr/bin/env bash
echo "Hello from Bash"
```


`#!/usr/bin/env bash` finds `bash` on your `PATH`, which is more portable than hard-coding `/bin/bash`. If the file was edited on Windows, it may have CRLF line endings, which make the interpreter path end in an invisible carriage return. Check and fix that with:


```bash
file script.sh          # reports "with CRLF line terminators" if affected
sed -i 's/\r$//' script.sh   # GNU sed; on macOS use: sed -i '' 's/\r$//' script.sh
```


### Work around a noexec mount


First confirm it is the problem. `findmnt` is available on most Linux systems:


```bash
findmnt -T script.sh -o TARGET,OPTIONS
# or, more generally
mount | grep noexec
```


If the options include `noexec`, either move the script somewhere that allows execution, or pass it to the interpreter yourself. Running `bash script.sh` reads the file as input instead of executing it, so it does not need the execute bit:


```bash
bash script.sh
```


Do not remount system filesystems without `noexec` just to run a script. That option is usually there on purpose.


### Running it with sudo does not help


`sudo ./script.sh` still needs the execute bit, and running scripts as root to dodge a permission error is a habit worth avoiding. Fix the permission instead.


## Common pitfalls

- Running `chmod +x` on a copy, then executing the original. Check with `ls -l` that the `x` appears on the file you are actually running.
- Forgetting the `./`. Typing `script.sh` on its own makes the shell search your `PATH`, so you get `command not found` rather than running the file in the current directory.
- Expecting `chmod` to work on a `noexec` mount or a Windows drive mounted in WSL with restrictive options. The permission change may be silently ignored.
- A `Permission denied` on a directory in the path. You need execute permission on every directory leading to the script to reach it.
- Committing a script without the executable bit, so it works on your machine and fails in CI. Use `git update-index --chmod=+x`.

## Related reading

- [GNU Coreutils: chmod invocation](https://www.gnu.org/software/coreutils/manual/html_node/chmod-invocation.html)
- [Bash Reference Manual: Shell Scripts](https://www.gnu.org/software/bash/manual/html_node/Shell-Scripts.html)
