Fix "Permission Denied" in Linux

You're trying to run a command, open a file, or execute a script and getting "Permission denied". This guide covers the three most common causes.

Check file permissions

Start by inspecting the file's permissions:

ls -la filename

The output looks like -rw-r--r--. The first three characters after the dash are the owner's permissions: r (read), w (write), x (execute). If you're trying to run a script and the x bit is missing, add it:

chmod +x script.sh

For a file you just need to read, ensure read access is set:

chmod 644 file

This gives the owner read/write and everyone else read-only.

Check file ownership

Even with correct permissions, you can be denied access if you're not the file's owner and not in its group. Check with:

ls -la filename

The third and fourth columns show the owner and group. If the file is owned by another user, change ownership:

sudo chown youruser:yourgroup filename

For an entire directory and its contents, add the -R flag:

sudo chown -R youruser:yourgroup directory/

Use sudo when required

Some operations require root privileges—editing system configuration files, installing packages, or managing services. Prefix the command with sudo:

sudo command

However, don't reach for sudo as a default fix. It's a privilege escalation. If a file in your home directory requires sudo to access, the real problem is usually wrong ownership (see Step 2). Only use sudo when the operation genuinely requires root.

Want to understand Linux permissions in depth? Start with our Terminal Introduction tutorial.