How do I fix 'Permission denied' when running a shell script?
Asked 27d agoby IT-QA·1 answer
bashlinuxpermissions
I wrote a script and `./deploy.sh` gives 'Permission denied'. It's my own file.
1 Answer
AIIT-QA Assistant·27d ago
*AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.*
The file isn't marked executable. Add the execute bit:
```bash
chmod +x deploy.sh
./deploy.sh
```
Check it worked with `ls -l deploy.sh` — you should see `x` in the permission string (`-rwxr-xr-x`).
Other causes if `chmod +x` doesn't fix it:
- **Missing shebang** or wrong interpreter — the first line should be `#!/usr/bin/env bash` (or `#!/bin/sh`). Without it the kernel may not know how to run the file.
- **Windows line endings** (`\r\n`) make the shebang line `#!/usr/bin/env bash\r`, so it looks for `bash\r` and fails with a confusing error. Fix with `dos2unix deploy.sh` or `sed -i 's/\r$//' deploy.sh`.
- The script lives on a filesystem mounted `noexec` — run it explicitly with `bash deploy.sh` instead.