Grant Executable Access to file


I assume you might have came across this topic and happened with you that you might have tried to open a file or run a script(.sh) file but you failed to do so.
This may due to the file do not have the required permission to perform the action.
In such cases we need to provide the permission to it.
Here we will look into how we can provide the permission to the file.
Lets take the Scenario :
In a bid to automate backup processes, the xFusionCorp Industries sysadmin team has developed a new bash script named xfusioncorp.sh. While the script has been distributed to all necessary servers, it lacks executable permissions on App Server 3 within the Stratos Datacenter.
Your task is to grant executable permissions to the /tmp/xfusioncorp.sh script on App Server 3. Additionally, ensure that all users have the capability to execute it.
In Linux, to execute a script, the user must have both read and execute permissions on the file. However, the requirement here is only to make it executable for all. So if the script is not readable by others, then others still won't be able to execute it. But the task does not require us to make it readable, only executable.
Since the task is specific: "grant executable permissions", we do exactly that. If there are issues with execution, then we might need to adjust read as well, but that is beyond the current task.
It’s very eassy pessy task let note the command according to scenario provided above.
- Connect to App Server 3:
Use SSH to access the server:
ssh banner@stapp03
- Add executable permissions for all users:
Run:
sudo chmod a+x /tmp/xfusioncorp.sh
a+x : Grants execute ( x ) permission to all users (owner + group + others).
sudo : Ensures administrative privileges if required.
Verify:
Check permissions with:
ls -l /tmp/xfusioncorp.sh
Output should show x
in all 3 permission sets (e.g., -rwxr-xr-x
).
Key Notes:
Solves: Script lacks executable permissions.
Ensures: Every user can run the script (
a+x
covers all).Location: Script is at
/tmp/
xfusioncorp.sh
.
There is one other way as well we can provide permission through numeric value as well.
To grant executable permission to a .sh file in Linux using numeric notation, you can use the chmod command. Here's how:
7: Full permissions (read, write, execute) for the owner.
5: Read and execute permissions for the group.
5: Read and execute permissions for others.
This ensures the script is executable by the owner, group, and others while maintaining security by not allowing write access to group and others.
If you want to give executable permission to everyone without restrictions, you can use:
chmod 777 filename.sh
However, this is not recommended for security reasons.
Subscribe to my newsletter
Read articles from Kunal Kumar Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Kunal Kumar Singh
Kunal Kumar Singh
I am a DevOps Engineer working in MNC. Where I automate Infrastructure using various DevOps tools and AWS Cloud.