Linux Exit Code 126 — Permission Denied
About Linux Exit Code 126
Linux exit code 126 means the command was found but cannot be executed due to missing execute permission. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: bash: ./script.sh: Permission denied. File exists but lacks execute permission. Common with downloaded scripts and binaries. Different from exit code 127 (not found). Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: File missing execute permission bit. Script downloaded without execute permission. File on a noexec-mounted filesystem. SELinux blocking execution. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Add execute permission: chmod +x script.sh. Or run with interpreter: bash script.sh. Check mount options for noexec: mount | grep noexec. Check SELinux: ls -Z script.sh. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
Why was my script not executable?
Downloaded files typically do not have execute permission — use chmod +x to add it.
Overview
Linux exit code 126 means the command was found but cannot be executed due to missing execute permission.
Key Details
- bash: ./script.sh: Permission denied
- File exists but lacks execute permission
- Common with downloaded scripts and binaries
- Different from exit code 127 (not found)
Common Causes
- File missing execute permission bit
- Script downloaded without execute permission
- File on a noexec-mounted filesystem
- SELinux blocking execution
Steps
- 1Add execute permission: chmod +x script.sh
- 2Or run with interpreter: bash script.sh
- 3Check mount options for noexec: mount | grep noexec
- 4Check SELinux: ls -Z script.sh