How to Add Execution Permission on Linux
You can add execution permission on Linux with the chmod command, most commonly by running chmod +x filename. This makes a file executable, which is useful for shell scripts and other programs. If the file is a script, it usually also needs a valid shebang line so Linux knows which interpreter to use.
What execute permission means on Linux
Linux file permissions control who can read, write, or execute a file. Execute permission tells the system that a file can be run as a program. For scripts, execute permission is only part of the requirement, the file also needs to contain valid script content and usually an interpreter line at the top.
In a typical ls -l listing, the execute bit appears as x in the permission string. For example, a non-executable file might look like this:
-rw-r--r-- 1 user user 1240 May 10 09:00 backup.shAfter adding execute permission, it may look like this:
-rwxr-xr-x 1 user user 1240 May 10 09:00 backup.shHow to add execution permission on Linux with chmod
The simplest way to add execution permission on Linux is to use chmod +x followed by the file name.
chmod +x backup.shThis adds execute permission for the file owner, group, and others, while keeping the existing read and write permissions unchanged.
If you only want to add execute permission for specific users, you can use symbolic modes.
chmod u+x backup.sh # add execute permission for the owner
chmod g+x backup.sh # add execute permission for the group
chmod o+x backup.sh # add execute permission for othersYou can also combine them:
chmod u+x,g+x backup.shMake a script executable with chmod +x
For shell scripts, chmod +x is the most common method. After setting the permission, you can run the script directly if the current directory or the script path is specified.
chmod +x install.sh
./install.shHere are the basic steps:
- Open the terminal and go to the directory containing the file.
- Check the current permissions with
ls -l. - Run
chmod +x filename. - Verify the change with
ls -lagain. - Run the file using
./filenameor its full path.
For scripts, make sure the first line points to the correct interpreter. A Bash script often starts with:
#!/bin/bashAnother common option is:
#!/usr/bin/env bashWithout a valid shebang, Linux may not know how to execute the file even if it has execute permission.
Use numeric permissions like 755
Some users prefer numeric permission modes instead of symbolic ones. The most common example for an executable script is chmod 755.
chmod 755 backup.shThis sets the permissions to:
- 7 for the owner, read, write, and execute
- 5 for the group, read and execute
- 5 for others, read and execute
Use numeric mode when you want precise control over permissions. Use chmod +x when you simply want to add execute permission without changing the rest of the file mode.
| Command | What it does | Best use case |
|---|---|---|
chmod +x file | Adds execute permission without changing other bits | Quickly making a file runnable |
chmod u+x file | Adds execute permission for the owner only | Restricting execution to the file owner |
chmod 755 file | Sets owner, group, and others to read and execute, owner can also write | Common for public scripts |
Check permissions with ls -l
Use ls -l to confirm whether the execute bit was added correctly.
ls -l backup.shExample output before and after:
-rw-r--r-- 1 user user 1240 May 10 09:00 backup.sh
-rwxr-xr-x 1 user user 1240 May 10 09:00 backup.shThe x characters show that the file is executable. If you do not see x, the file still is not executable for that user class.
If the script still will not run
If you added execute permission but the file still does not run, the problem is usually one of these issues:
- Missing shebang, the script does not specify an interpreter.
- Wrong interpreter path, such as a shebang pointing to a shell that does not exist on the system.
- Permission denied, the file system or ownership may prevent execution.
- Not the file owner, you may need
sudoor the correct user account to change permissions. - Wrong line endings, scripts created on Windows may contain carriage returns that break execution.
Useful checks include:
file backup.sh
head -n 1 backup.sh
ls -l backup.shIf the script belongs to another user and you have admin rights, you may need:
sudo chmod +x backup.shUse sudo carefully. Only change permissions on files you trust and understand.
Common mistakes to avoid
- Using recursive chmod too broadly, for example
chmod -R +xcan accidentally make many files executable, including files that should not be. - Applying execute permission to the wrong file, such as a data file that is not meant to be run.
- Skipping the shebang in scripts, which often leads to execution errors.
- Changing permissions instead of ownership, when the real issue is that the file is owned by the wrong user or group.
- Making downloaded files executable without checking them, which can be risky if the source is untrusted.
When to use chmod +x versus chmod 755
Both commands can make a file executable, but they are not identical.
chmod +xadds execute permission while preserving the existing read and write settings.chmod 755overwrites the permissions with a specific standard pattern.
If you only want to enable execution and leave everything else as-is, use chmod +x. If you want a predictable permission set for a script, chmod 755 is often used.
Best practices for executable files
- Only grant execute permission to files you trust.
- Use
ls -lto verify the result after changing permissions. - For scripts, include a valid shebang line.
- Use the least permissive setting that still works for your needs.
- Avoid changing permissions recursively unless you really intend to modify many files.
Frequently Asked Questions About how to add execution permission on linux
How do I add execution permission on Linux?
Use chmod +x filename. This adds execute permission to the file so it can be run directly.
What does chmod +x do in Linux?
It adds the execute bit to a file while keeping the other permissions unchanged.
How do I make a script executable in Linux?
Add execute permission with chmod +x script.sh, then run it with ./script.sh. Also make sure the script has a valid shebang line.
What is the difference between chmod 755 and chmod +x?
chmod +x only adds execute permission, while chmod 755 sets a full permission pattern with specific read, write, and execute bits.
How do I check file permissions in Linux?
Use ls -l filename. The permission string at the start of the output shows whether execute permission is set.
Why is my Linux script not executable?
Common causes include missing execute permission, a missing or incorrect shebang, wrong file ownership, or line ending issues.
Conclusion
The fastest way to add execution permission on Linux is usually chmod +x filename. If you want a more specific permission set, use a numeric mode such as chmod 755 filename. After changing permissions, confirm the result with ls -l, and if the file is a script, make sure it has a valid shebang so Linux can run it correctly.
