Skip to main content
← All guides

Fixing "Permission denied" (file permissions)

On Linux, Permission denied means "this account doesn't have permission to handle this file that way." It's almost always one of the three cases below, so checking them in order usually fixes it quickly.

How to read permissions

ls -l
-rwxr-xr-- 1 kim botteam 1024 Oct  8 12:00 start.sh
  • Read the leading -rwxr-xr-- in three groups: owner (rwx) / group (r-x) / everyone else (r--)
  • r read, w write, x execute (for folders, enter)
  • kim is the owner and botteam is the group.

Case 1. The file was made with sudo, so your account can't edit it (most common)

Files created or unzipped with sudo are owned by root, so your account can't modify them. Change the owner to your account.

sudo chown -R $USER:$USER ~/myfolder

If you get into the habit of not adding sudo when you work inside your own folders, this problem will hardly ever come up.

Case 2. The script doesn't have execute permission

If running ./start.sh gives Permission denied, give it execute permission.

chmod +x start.sh

Case 3. Tasks that need administrator privileges

Installing programs (apt install), editing system configuration files (/etc/...) and opening ports below 1024 (80, 443) need administrator privileges. Put sudo in front of the command.

sudo nano /etc/nginx/sites-available/example.com

When your SSH key is rejected

For security, SSH won't use a key if the permissions on the key file and folder are too open. On the server:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

The same goes for the private key on your PC (Linux, macOS). (chmod 600 ~/.ssh/id_ed25519)

Never do this: chmod 777

chmod -R 777 means "anyone may read, write and execute." Even if the error goes away for now, any other program or person that gets into your server can change your files however they like. Fix it with the methods above (changing the owner, giving execute permission).

If it still doesn't work

  • Check which account you're running as: whoami
  • Check the parent folders' permissions too: namei -l ~/myfolder/filename (shows the permissions of every folder in the path at once)
  • If the program runs under systemd, check that the User= account in the service file has permissions on that folder.

For sharing a folder with a friend, see Creating a server account for a friend.

If your problem isn't solved, open a ticket on our Discord.