chmod +x
chmod +x file adds the execute bit so the file can be run directly (./file). With no u, g, o or a in front, it applies to all three classes except the ones your umask masks, so with the usual umask 022 it is the same as a+x.
Results on common starting modes
| Before | After, umask 022 | After, umask 077 |
|---|---|---|
644 rw-r--r-- | 755 rwxr-xr-x | 744 rwxr--r-- |
600 rw------- | 711 rwx--x--x | 700 rwx------ |
640 rw-r----- | 751 rwxr-x--x | 740 rwxr----- |
664 rw-rw-r-- | 775 rwxrwxr-x | 764 rwxrw-r-- |
444 r--r--r-- | 555 r-xr-xr-x | 544 r-xr--r-- |
Who gets execute: the umask rule
When a symbolic mode names no users, chmod treats it as a (all users) but leaves alone any bit that is set in your umask. The GNU coreutils manual describes this in "The Umask and Protection". Your umask decides the outcome: with 022 no execute bit is masked, so everyone gets x; with 077 group and others are masked, so only the owner gets x.
That is why chmod +x on a 600 file can produce 711: the owner gains x, and so do group and others. They still cannot read it, so a script stays unusable to them, but a compiled binary becomes runnable. Use u+x when you mean the owner only.
Running the file afterwards
Execute permission lets the kernel run the file. A script also needs a first line naming its interpreter, such as #!/bin/sh or #!/usr/bin/env python3, and the calling user needs read access so the interpreter can open it.
If ./script.sh still says Permission denied after chmod +x, check whether the filesystem is mounted noexec (common for /tmp, /dev/shm and USB drives): findmnt shows the options, and bash script.sh works regardless because it only reads the file.
chmod +x deploy.sh
./deploy.sh
findmnt -no OPTIONS --target deploy.sh # look for noexecKeeping the execute bit in Git
Git records only whether a file is executable: mode 100755 when the owner execute bit is set, 100644 otherwise. On Windows, or any checkout where core.fileMode is false, chmod has no effect on what Git stores, so set the bit in the index instead.
git add --chmod=+x deploy.sh
# or, for a file already tracked:
git update-index --chmod=+x deploy.sh
git ls-files -s deploy.sh # shows 100755Frequently asked questions
- What does chmod +x do?
- It adds execute permission, so the file can be run as a program. Under the common umask 022 it gives execute to the owner, the group and others.
- What is the difference between chmod +x and chmod 755?
- chmod +x only adds execute bits and keeps everything else. chmod 755 replaces the whole mode. On a 644 file both give 755; on a 600 file +x gives 711 and 755 would also make it readable by everyone.
- Should I use chmod +x or chmod u+x?
- u+x when only you should run it, or when you want a result that does not depend on the umask. +x for scripts everyone on the machine may run.
- How do I remove execute permission?
- chmod -x file removes it (subject to the same umask rule); chmod a-x file removes it from everyone regardless of the umask.
Last reviewed by Arielton Oberek.