Windows 10 Cygwin Error: /bin/bash: Exit 126. Failed to Run /bin/bash: Permission Denied - A Quick Guide to Troubleshooting

Abstract: Resolve Windows 10 Cygwin exit code 126 permission denied errors by fixing file permissions, converting CRLF line endings, and clearing security attributes.

Created: 2026-09-10 by

The exit code 126 in Cygwin indicates that the system found the executable but lacks permission to run it. This is a security feature where Windows prevents scripts or binaries from executing due to incorrect file attributes or ownership issues. You can resolve this by correcting file permissions, ensuring proper line endings, and verifying that the files are not blocked by Windows Defender.

Understanding Exit Code 126

When you attempt to execute a script or binary in Cygwin and receive /bin/bash: Exit 126. Failed to Run /bin/bash: Permission Denied, it is crucial to distinguish between two similar error codes. Exit code 127 means "command not found," implying the file does not exist or is not in your path. Exit code 126 means "permission denied," meaning the file exists, but the operating system refuses to execute it. In the context of Windows 10 and Cygwin, this refusal usually stems from one of three causes: 1. The file lacks the executable bit set in the Cygwin environment. 2. The file has Windows-specific security attributes (like "Mark of the Web") that prevent execution. 3. The file contains invalid characters, such as Windows-style carriage returns (CRLF) instead of Unix-style line feeds (LF), which confuses the bash parser. This issue often arises after copying files from another machine, downloading archives, or using version control systems that do not preserve Unix permissions correctly. It is a common friction point for users migrating from Linux environments to Windows. For deeper insights into how Cygwin handles these specific security quirks, you may want to review Troubleshooting Cygwin's Weird Behavior on Security Permissions.

Step-by-Step Troubleshooting Guide

Follow these steps in order to isolate and fix the permission denied error. Start with the simplest fixes before moving to more complex attribute corrections.

1. Verify File Existence and Path

First, ensure the file actually exists at the specified location. Use the ls -l command to check if the file is visible and see its current permissions.
ls -l /path/to/your/script.sh
If the file is listed, note the permission string. It should start with -rwxr-xr-x or similar, indicating read, write, and execute rights. If it starts with --w--w--w- or lacks the x (execute) bits, this is likely the primary cause.

2. Add Execute Permissions

Cygwin relies on POSIX permissions. If you created the file using Notepad or copied it from Windows Explorer, it may not have the execute bit set. Use the chmod command to add execute permissions for the user, group, and others.
chmod +x /path/to/your/script.sh
After running this command, try executing the script again. If it works, the issue was simply missing execute flags. If you still get an error, proceed to the next step.

3. Check for Windows Line Endings (CRLF)

Windows uses Carriage Return + Line Feed (CRLF) for text files, while Unix/Linux uses only Line Feed (LF). If your script was edited on Windows, it likely contains CRLF sequences. Bash interprets the carriage return character (\r) as part of the command name. For example, instead of running ./script.sh, it tries to run ./script.sh\r, which fails with a permission or not found error. To check for this, use the file command:
file /path/to/your/script.sh
If the output says "with CRLF line terminators," you need to convert the file. You can use dos2unix if installed, or configure your editor to save with Unix line endings.
dos2unix /path/to/your/script.sh
Alternatively, you can use sed to remove carriage returns:
sed -i 's/\r$//' /path/to/your/script.sh

4. Remove Windows "Mark of the Web"

Windows adds a zone identifier to downloaded files or files moved from other drives to prevent automatic execution. This is known as the "Mark of the Web." Cygwin respects these NTFS alternate data streams, which can block execution even if POSIX permissions are correct. You can remove this mark using PowerShell. Open PowerShell as Administrator and run:
Unblock-File -Path "C:\cygwin64\home\user\script.sh"
Replace the path with the actual path to your script. This removes the zone identifier that Windows uses to flag the file as potentially unsafe.

5. Check Antivirus and Windows Defender

Sometimes, real-time protection software interferes with Cygwin's execution engine. If the above steps fail, temporarily disable your antivirus or Windows Defender real-time protection to see if the script runs. If it does, add an exclusion for your Cygwin home directory or the specific script. For more information on managing permissions in Cygwin, consider reading Bash Binutils Configure Permission Denied, which covers similar permission hurdles during compilation.

Preventing Future Issues

To avoid encountering this error repeatedly, adopt the following practices:
  • Use Proper Editors: Use editors like VS Code, Sublime Text, or Vim that allow you to explicitly set line endings to LF. Avoid saving scripts in standard Notepad unless you are sure to change the encoding settings.
  • Version Control: Use Git with core.autocrlf set appropriately. In a Cygwin environment, setting core.autocrlf=input ensures that files checked out retain their Unix line endings regardless of the platform they were committed from.
  • Consistent Permissions: When cloning repositories, ensure that the repository preserves executable bits. Some platforms strip these bits when syncing with Windows filesystems.
By understanding the interplay between Windows security features and POSIX standards, you can maintain a smooth development environment without constant permission errors.

Frequently Asked Questions

Why does chmod not fix the error?

chmod only modifies POSIX permissions stored in Cygwin's internal database. If the underlying Windows NTFS attributes (like the Mark of the Web) or line ending issues are present, chmod will not override them. You must address the Windows-specific markers separately using tools like Unblock-File or dos2unix.

Can I ignore the Mark of the Web permanently?

You can configure Windows to automatically unblock files upon download via Group Policy, but this is generally discouraged for security reasons. A safer approach is to use PowerShell scripts to unblock specific directories used for development, rather than disabling the feature globally.

Does this error occur in WSL as well?

While less common, WSL can also face permission issues if files are shared directly between Windows and Linux partitions without proper handling. However, WSL2 typically handles line endings and permissions differently than Cygwin. For related troubleshooting in WSL, see Bash Source Command Silently Fails in WSL2 vs Direct Executions in Shell?.

How do I check if my script has CRLF endings?

Run the file command on the script. If it outputs "with CRLF line terminators," it has Windows-style endings. You can also open the file in a hex editor to look for the byte sequence 0D 0A (CR+LF) instead of just 0A (LF).

Is it safe to disable Windows Defender for Cygwin?

It is not recommended to disable Windows Defender entirely. Instead, add an exclusion for your Cygwin root directory (e.g., C:\cygwin64) or your project folders. This allows Cygwin to execute scripts freely while keeping the rest of your system protected against malware.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More