Every file and folder on Linux has an owner, a group and permissions. They decide who may read it, change it, or run it as a program. When something answers Permission denied, the permissions are usually the reason. The commands were tested on Ubuntu 26.04 LTS with a test user; run them as root.


1. Read the Permissions

ls -l /srv/files
-rw------- 1 root root   11 Nov 28 03:33 secret.txt
drwxr-xr-x 2 root root 4096 Nov 28 03:33 shared
  • The first letter: - a file, d a folder.
  • Then three groups of three letters, for the owner, the group and everyone else: r read, w write, x run (for a folder: open it).
  • Then the owner and the group, here root root.

So secret.txt can be read and changed only by root. Another user gets Permission denied when reading it, but can read files in shared, which everyone may read (r-x).

2. Change Them With Numbers

Each group is a number: read 4 + write 2 + run 1. The most common values:

  • chmod 600 file: only the owner may read and write. For passwords and keys.
  • chmod 644 file: the owner may write, everyone may read. Normal files.
  • chmod 755 folder or script: everyone may open the folder or run the script, only the owner may change it.

A script that answers Permission denied when you start it needs the right to run: chmod +x run.sh.

3. Change the Owner

chown alex:alex /srv/files/report.pdf
chown -R alex:alex /srv/files

-R changes a folder and everything in it. Check the path twice: a wrong chown -R on a system folder can stop programs from working.

4. A Folder for a Team

To let several users work in one folder, give them a common group:

groupadd team
usermod -aG team alex
chown -R root:team /srv/shared
chmod 2775 /srv/shared

The 2 in front makes new files in the folder belong to the group team; ls -ld then shows an s: drwxrwsr-x. Users in the group can now create files in the folder. A user added to a group has to log in again before it counts.

New files are created with the user's default permissions, usually 644, so other team members can read but not change them. If they should, run chmod g+w on the files.

Users and sudo: Add Users and Give Them sudo on Your Linux Server.


Related Guides

View all Linux guides

Was this answer helpful? 0 Users Found This Useful (0 Votes)