Skip to content
FR EN

Fix “Permission denied” on Linux

Time 6 min Level Intermediate Updated

Linux gives every file an owner plus read (r), write (w) and execute (x) permissions. The error appears when one of them is missing.

  1. Read the file's permissions

    ls -l script.sh
    bash

    The output looks like -rw-r--r-- 1 root root: no x, so it can't run, and root owns it.

  2. Make a script executable

    chmod +x script.sh
    ./script.sh
    bash
  1. Take ownership of a file

    If root owns a file inside your home folder:

    sudo chown $USER:$USER script.sh
    bash
  2. Use sudo for system files

    Files in /etc or /usr need admin rights, for example sudo nano /etc/hosts.

Good to know : Never use chmod 777 to “fix” it: anyone could then modify the file.

Read next