Skip to content

Linux Foundations / Manage a Linux host ยท Step 7 of 50

Lesson: File PermissionsSwitch
โ† Linux Foundations

System administration

File Permissions

Read the permission string that ls shows and understand what read, write and execute mean for files and directories.

Every file on Linux carries a small set of rules that say who may read it, change it or run it. Once you can read those rules, many "Permission denied" errors stop being mysterious.

Reading the permission string

Use ls -l to see them:

$ ls -l notes.txt deploy.sh
-rwxr-xr-x 1 maya devs 220 Mar  3 10:12 deploy.sh
-rw-r----- 1 maya devs  58 Mar  3 10:10 notes.txt

The first character is the file type: - is a regular file, d is a directory and l is a symbolic link. The next nine characters are three groups of three:

  • characters 2 to 4: the owner (here maya)
  • characters 5 to 7: the group (here devs)
  • characters 8 to 10: others, meaning everyone else

In each group, r is read, w is write, x is execute, and - means that permission is missing. So notes.txt can be read and written by maya, only read by members of devs, and not touched by anyone else.

Which group of three applies to you

Linux picks one class and stops. If you own the file, only the owner bits count. Otherwise, if you belong to the file's group, only the group bits count. Otherwise the "others" bits apply. The classes are not added together, so an owner with --- is refused even if others have r. The root user can bypass most of these checks.

Directories are different

On a directory, the same letters mean something else:

  • r lets you list the names inside it
  • w lets you create, delete and rename entries (it needs x as well)
  • x lets you enter it and reach the files inside

Use ls -ld to see the directory itself rather than its contents:

$ ls -ld reports
drwxr-x--- 2 maya devs 4096 Mar  3 10:20 reports

Because deleting a file changes the directory, not the file, your right to remove a file comes from the directory's permissions.

Some systems add a . or + after the nine characters. These indicate an SELinux context or an access control list (ACL), which can add further rules.

Try it

Run these in your home directory:

$ ls -l
$ ls -ld . /etc /root
$ id

For each line, work out whether you are the owner, a group member or "other", then predict what you can do. You can practise on a real shell in the permissions lab.

Check your understanding

File Permissions

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.