Fix: Permission denied when running a script (chmod +x)
bash: ./script.sh: Permission denied means the file exists but you may not execute it. Usually the execute bit is missing; sometimes the file system is mounted noexec or the file belongs to someone else.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
bash: ./deploy.sh: Permission denied
zsh: permission denied: ./deploy.sh
-bash: /opt/app/run.sh: Permission denied
The shell found the file but the kernel refused to run it. Running a file needs the execute permission bit on the file for your user, read permission for the interpreter to read it, and a file system that allows execution at all.
Cause 1: the execute bit is not set
This is by far the most common case. Files created by an editor, downloaded, extracted from a zip or copied from Windows have no execute bit.
ls -l deploy.sh
# -rw-r--r-- 1 alice alice 512 Oct 10 09:12 deploy.sh <- no x anywhere
chmod +x deploy.sh # or chmod u+x to allow only the owner
./deploy.sh
If you cannot or do not want to change the file, run it through the interpreter instead; that only requires read permission: bash deploy.sh or python3 tool.py.
Cause 2: the file system is mounted noexec
Many systems mount /tmp, /dev/shm, home directories on shared storage, USB sticks, and some network shares with the noexec option. chmod +x succeeds but execution is still refused.
findmnt -T deploy.sh
# TARGET SOURCE FSTYPE OPTIONS
# /tmp tmpfs tmpfs rw,nosuid,nodev,noexec,relatime
# Either run through the interpreter
bash /tmp/deploy.sh
# or move the script somewhere executable
mv /tmp/deploy.sh ~/bin/ && ~/bin/deploy.sh
Cause 3: you are not the owner and the mode excludes you
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
ls -l /opt/app/run.sh
# -rwx------ 1 root root 2048 Oct 10 09:12 run.sh <- only root may read or run it
sudo /opt/app/run.sh # run as root if that is intended
sudo chown alice:alice /opt/app/run.sh # or make yourself the owner
sudo chmod 755 /opt/app/run.sh # or let everyone read and execute
Careful: chmod 777 and chmod -R on system directories are common mistakes that open files to every user and can break sudo or SSH, which refuse to work with overly open permissions. Change only the file you need, to the least permission that works.
Cause 4: a directory on the way is not searchable
To reach /opt/app/run.sh you need execute (search) permission on /opt and /opt/app. namei -l /opt/app/run.sh prints the permission of every component so you can see which one blocks you.
Check that it is fixed
ls -l deploy.sh # shows x for your user, for example -rwxr-xr-x
./deploy.sh && echo "ran fine"
When it is not what you think
bad interpreter: Permission deniednames the interpreter in the shebang line, which may itself be non-executable or on a noexec mount, for example a Python inside a virtual environment under/tmp.Permission deniedfrom a command inside the script (for example writing to/var/log) is about that command’s target, not about running the script. Read the full line: it names the file it could not open.- A script that must bind a port below 1024, read
/etc/shadowor write to/etcneeds root: run it withsudo, or give the binary a capability such ascap_net_bind_service. Permission denied (publickey)is SSH refusing your key, nothing to do with file modes on the client.- SELinux can deny execution of a file with the right mode.
ausearch -m avc -ts recentshows a denial;restorecon -v filefixes a wrong label.
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0049 Pipes and redirection: connecting commands A pipe sends one command's output into another command, and redirection sends output to a file. Together they let small tools build… Beginner · Explains an idea · Linux, macOS Article Basics · Text processing 15 Oct 2026
- 0050 File permissions: chmod, chown and what 755 means Every file has an owner, a group and read/write/execute permissions for three kinds of users. chmod changes the permissions and chown changes… Beginner · Explains an idea · Linux, macOS Article Basics 15 Oct 2026
- 0051 Environment variables and PATH Environment variables are named settings that every program inherits from the shell. PATH is the one that tells the shell where to… Beginner · Explains an idea · Linux, macOS Article Basics 15 Oct 2026
- 0057 Shell cheat sheet: everyday commands A quick reference for moving around, managing files, viewing and searching text, checking processes and disk space in bash and zsh, with… Beginner · Cheat sheet · Linux, macOS Article Basics · Command-line tools 15 Oct 2026
- 0177 Users, groups and sudo on Debian, Ubuntu and RHEL How Linux accounts and groups work, how to create users, and how sudo gives admin rights through the sudo group on Debian/Ubuntu… Beginner · Explains an idea · Linux Article Users, sudo & hardening 15 Oct 2026
- 0178 Create a sudo user with an SSH key and disable password login A bash script that creates an admin user in the sudo or wheel group, installs their SSH public key and can switch… Advanced · Step by step · Linux Script Keys & config · Users, sudo & hardening 15 Oct 2026
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,352 chars