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

Steps

  1. Look at the current permissions

    Run ls -l deploy.sh and 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.sh
  2. Add execute for the owner

    Type u+x in Apply a change and press Apply. The mode becomes 744: you can read, write and run it, and others can only read it.

  3. Decide who else may run it

    If teammates on the same machine need to run it, apply go+x as well to get 755. Never give write access to others on a script, because anyone could change what it does.

  4. Copy the command and run it

    Type deploy.sh in 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.

Try it now

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 with bash deploy.sh or 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.