chmod Calculator · Tutorial
How to fix "Permission denied" when running a script
5 min readbeginnerUpdated
You run ./deploy.sh and the terminal answers “Permission denied”. Usually the file is missing its execute permission. You will read the current permissions, add execute safely and check the result before running chmod.
What you need
- The chmod Calculator
- A terminal on Linux or macOS
Steps
Look at the current permissions
Run
ls -l deploy.shand copy the first column, for example-rw-r--r--. Paste it into Symbolic. The summary shows that nobody can run the file: there is no x anywhere.$ ls -l deploy.sh -rw-r--r-- 1 ana staff 812 Nov 1 09:12 deploy.shAdd execute for the owner
Type
u+xin Apply a change and press Apply. The mode becomes 744: you can read, write and run it, and others can only read it.Decide who else may run it
If teammates on the same machine need to run it, apply
go+xas well to get 755. Never give write access to others on a script, because anyone could change what it does.Copy the command and run it
Type
deploy.shin File or folder name and copy the command. Run it, then try the script again.chmod 744 deploy.sh ./deploy.sh
Try it yourself
Opens the chmod Calculator with this tutorial's sample loaded.
Common mistakes
- Using chmod 777 to make the error go away
- It works, but it lets everyone change the script. The calculator warns you about this. Use 744 or 755 instead.
- The folder is the problem
- If the script is on a drive mounted with
noexec, or a folder you can’t enter, execute permission on the file doesn’t help. Run it withbash deploy.shor move it. - Windows line endings
- A script saved with Windows line endings fails with “bad interpreter” even with execute set. Convert it to Unix line endings.
Next steps
Go back to the chmod Calculator, or keep going with one of these:
FAQ
Why does `bash deploy.sh` work without execute permission?
Then bash is the program being run, and it only needs to read the file. ./deploy.sh asks the system to run the file itself, which needs execute.