Error Codes Wiki

chmod Permission Denied on Script — Making Shell Scripts Executable on Linux

Informationalpermissions

Overview

Fix permission errors when trying to run or chmod shell scripts on Linux, including execute permission, shebang lines, and filesystem restrictions.

Key Details

  • Shell scripts require execute (x) permission to run directly: chmod +x script.sh
  • The shebang line (#!/bin/bash) tells the kernel which interpreter to use for the script
  • Scripts on FAT32, NTFS, or noexec-mounted filesystems cannot be made executable
  • Even root cannot set execute permission on noexec filesystems
  • Scripts can always be run via the interpreter directly: bash script.sh (bypasses execute permission)

Common Causes

  • Script does not have execute permission (missing chmod +x after creation)
  • Script on a FAT32/NTFS partition that does not support Unix permissions
  • Filesystem mounted with noexec option preventing execution of any scripts/binaries
  • Script has Windows-style line endings (CRLF) causing the shebang to fail

Steps

  1. 1Add execute permission: 'chmod +x script.sh' then run with './script.sh'
  2. 2If chmod fails on FAT/NTFS: run the script via interpreter directly: 'bash script.sh'
  3. 3Check filesystem mount options: 'mount | grep noexec' — remount without noexec if appropriate
  4. 4Fix line endings: 'dos2unix script.sh' or 'sed -i "s/\r//" script.sh' for Windows-created scripts
  5. 5Verify shebang: first line should be #!/bin/bash or #!/usr/bin/env bash (with no leading spaces)

Tags

chmodpermissionsscriptexecuteshebang

More in Permissions

Frequently Asked Questions

'bash script.sh' launches bash and tells it to read the file as input — no execute permission needed on the file. './script.sh' asks the kernel to execute the file directly, which requires the execute permission bit to be set.