Fundamentals

File system permissions

Easy
30 min

You can use the command line at the bottom of the page to practice commands. Finally, complete the given tasks on the same command line.

Finally, let's look at file system permissions, or how file and folder permissions are interpreted and determined in a Linux environment.

Get a listing as shown in the image using the -l switch in the ls command.

In a Linux environment, both files and directories have permissions defined (inside the orange box) as well as an owner-user and an owner-group (inside the blue box).

Let's start with owners. Each user belongs to a group. So, as shown in the picture, the owner-user of each file is student (on the left) and the owner-group of each file is student (on the right).

-rwxr-xr-x 1 bob staff 72 Jun 6 19:49 test.sh

By default, the group is the same as the username and only the user belongs to that group, but this can also be defined differently. For example, the owner-user of the test.sh- file above is bob and the owner-group is staff.

File permissions are interpreted as follows:

Rights are defined in three categories, which are owner rights (orange), group rights (green), and other rights (blue). Example rights allow, therefore, that

  • The owner-user can read, write, and execute the specified file.
  • The owner group can read and execute the specified file.
  • Other users can read and execute the file in question.

Note! - Exceptionally, the directory must always have executable permissions if the directory is to be used as a working directory.

File permissions can be interpreted in two different ways. Either read, write and execute or octal, also known as numerical.

Numerical interpretation is done as follows.

  • Read (r) - 4
  • Write (w) - 2
  • Execute (x) - 1

For example, if the file permissions were rw- rw- r--, then the permissions would be interpreted numerically as 4+2 = 6, 4+2 =6 and 4. So in practice, the permissions rw- rw- r-- could also be interpreted as 664.

  • rw- or 6 - owner can read and write
  • rw- or 6 - owner group can read and write
  • r-- or 4 - other users can only read

The chmod command comes from the words change mode and it can be used to define permissions for files and directories. This can be done, for example, like this:

chmod 664 file.txt

The chown command comes from the words change owner and with this, both the owner and owner group of a file can be defined. This is done as follows:

chown owner:group file.txt

Training

Define the required permissions for the files according to the instructions.

Exercises

Task 1

Set ~/file1.txt permissions to rwx-rx-x

Task 2

Assign rx-r-r permissions to ~/file2.txt.

Task 3

Set ~/file3.txt permissions to w-w-w.

hakatemia pro

Ready to become an ethical hacker?
Start today.

As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.