What does chmod +x do? It makes a file executable, so you can run it

By TechCompare · Updated · How we check

chmod +x adds the execute bit so you can run the file as ./script.sh, and at umask 022 a 644 file ends up as rwxr-xr-x. Which bits it adds depends on the umask, so the result isn't the same on every system.

Run a script as ./script.sh and get 'Permission denied'? A script can't start directly until it has the execute bit. In ls -l, a 644 file shows as -rw-r--r-- before chmod +x and as -rwxr-xr-x after it, at umask 022. Only the x letters change.

Command
chmod +x
Adds the execute bit
Result at umask 022
755
rwxr-xr-x from a 644 file
Result at umask 077
744
rwxr--r-- from a 644 file

How this is calculated

The chmod(1) man page sets the rule for a plain +x: "If none of these are given, the effect is as if (a) were given, but bits that are set in the umask are not affected." With no u, g, o or a in front, chmod adds execute for the owner, the group and others, except where the umask has that bit set. Many Linux systems default to umask 022, which blocks write for the group and others but not execute. A 644 file at that umask becomes 755. At umask 077, that file becomes 744, which is rwxr--r--, so only the owner can run it.

Each form handles the umask differently. chmod +x script.sh follows the umask, as above. chmod u+x script.sh gives execute to the owner only, so the 644 file becomes 744. chmod a+x script.sh gives it to everyone and ignores the umask, so that file becomes 755. There's also g+x for the group alone, which gives 654. With a letter in front, the umask doesn't come into it.

Some practical limits apply too. A script needs a first line such as #!/bin/bash to run directly. Without the execute bit, bash script.sh still runs it, because you name the interpreter yourself. A filesystem mounted noexec won't run programs at all, even when the bit is set.

Verdict

Only add the bit to files you wrote or have read. Skip it for data files, config files, and downloads you haven't checked, since a script runs whatever commands it contains. In a shared upload folder, leave the bit off. If only you run a script, u+x keeps the bit away from everyone else.

More CHMOD scenarios

Frequently asked questions

What's the difference between chmod +x and chmod 755?
chmod +x adds the execute bit to whatever bits the file already has, and the umask can block some of them. chmod 755 sets the whole mode to rwxr-xr-x no matter what the file had before. Use +x when you only need the run bit, and 755 when you want the full mode set in one step.
Why does chmod +x only make the file runnable by me?
The likely cause is a umask that blocks the group and others execute bits, such as 077. At umask 077, a 644 file becomes rwxr--r--, so only the owner can run it. To let everyone run it, use chmod a+x, which ignores the umask.
Why is my script still 'Permission denied' after chmod +x?
Check a few things. A filesystem mounted noexec won't run programs, even with the bit set. The bit also helps only the users it covers. The owner can run a file with u+x, but other users need a group or others execute bit. You also need execute on every folder in the path, since execute on a folder is what lets you enter it.
Can I make every script in a folder executable at once?
Not with -R. chmod -R +x dir marks every file inside, data files included, and chmod -R a+X dir only touches folders and files that already have an execute bit, so it leaves a plain 644 script alone. Name the scripts instead: chmod +x *.sh covers one folder, and find dir -name '*.sh' -exec chmod +x {} + covers the folders below it too.